Skip to content

Commit 1dd6906

Browse files
committed
Merge Bitwise and BitCount traits and remove from prelude, along with Bounded
One less trait in std::num, and three less exported in the prelude.
1 parent 149fc76 commit 1dd6906

File tree

21 files changed

+45
-42
lines changed

21 files changed

+45
-42
lines changed

src/etc/vim/syntax/rust.vim

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ syn keyword rustTrait OrdIterator MutableDoubleEndedIterator ExactSize
8383
syn keyword rustTrait Times
8484

8585
syn keyword rustTrait Algebraic Trigonometric Exponential Hyperbolic
86-
syn keyword rustTrait Bitwise BitCount Bounded
87-
syn keyword rustTrait Integer Fractional Real RealExt
86+
syn keyword rustTrait Bitwise Bounded Integer Fractional Real RealExt
8887
syn keyword rustTrait Num NumCast CheckedAdd CheckedSub CheckedMul
8988
syn keyword rustTrait Orderable Signed Unsigned Round
9089
syn keyword rustTrait Primitive Int Float ToStrRadix ToPrimitive FromPrimitive

src/libextra/enum_set.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
//! This module defines a container which uses an efficient bit mask
1414
//! representation to hold C-like enum variants.
1515
16+
use std::num::Bitwise;
17+
1618
#[deriving(Clone, Eq, IterBytes, ToStr, Encodable, Decodable)]
1719
/// A specialized Set implementation to use enum types.
1820
pub struct EnumSet<E> {

src/libextra/num/bigint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A `BigInt` is a combination of `BigUint` and `Sign`.
2222
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2323
use std::num;
2424
use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
25-
use std::num::{ToPrimitive, FromPrimitive};
25+
use std::num::{Bitwise, ToPrimitive, FromPrimitive};
2626
use std::rand::Rng;
2727
use std::str;
2828
use std::uint;

src/librustc/util/sha2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ static H256: [u32, ..8] = [
523523
#[cfg(test)]
524524
mod tests {
525525
use super::{Digest, Sha256, FixedBuffer};
526+
use std::num::Bounded;
526527
use std::vec;
527528
use std::rand::isaac::IsaacRng;
528529
use std::rand::Rng;

src/librustpkg/sha1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ impl Digest for Sha1 {
445445

446446
#[cfg(test)]
447447
mod tests {
448+
use std::num::Bounded;
448449
use std::rand::{IsaacRng, Rng};
449450
use std::vec;
450451
use extra::hex::FromHex;

src/libstd/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use cmath;
1717
use default::Default;
1818
use libc::{c_float, c_int};
1919
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
20-
use num::{Zero, One, strconv};
20+
use num::{Zero, One, Bounded, strconv};
2121
use num;
2222
use to_str;
2323
use unstable::intrinsics;

src/libstd/num/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cmath;
1818
use default::Default;
1919
use libc::{c_double, c_int};
2020
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
21-
use num::{Zero, One, strconv};
21+
use num::{Zero, One, Bounded, strconv};
2222
use num;
2323
use to_str;
2424
use unstable::intrinsics;

src/libstd/num/i16.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
18+
use num::{Bitwise, Bounded, CheckedAdd, CheckedSub, CheckedMul};
1919
use num::{CheckedDiv, Zero, One, strconv};
2020
use num::{ToStrRadix, FromStrRadix};
2121
use option::{Option, Some, None};
@@ -24,7 +24,7 @@ use unstable::intrinsics;
2424

2525
int_module!(i16, 16)
2626

27-
impl BitCount for i16 {
27+
impl Bitwise for i16 {
2828
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
2929
#[inline]
3030
fn population_count(&self) -> i16 { unsafe { intrinsics::ctpop16(*self) } }

src/libstd/num/i32.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
18+
use num::{Bitwise, Bounded, CheckedAdd, CheckedSub, CheckedMul};
1919
use num::{CheckedDiv, Zero, One, strconv};
2020
use num::{ToStrRadix, FromStrRadix};
2121
use option::{Option, Some, None};
@@ -24,7 +24,7 @@ use unstable::intrinsics;
2424

2525
int_module!(i32, 32)
2626

27-
impl BitCount for i32 {
27+
impl Bitwise for i32 {
2828
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
2929
#[inline]
3030
fn population_count(&self) -> i32 { unsafe { intrinsics::ctpop32(*self) } }

src/libstd/num/i64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use prelude::*;
1717
use default::Default;
1818
#[cfg(target_word_size = "64")]
1919
use num::CheckedMul;
20-
use num::{BitCount, CheckedAdd, CheckedSub};
20+
use num::{Bitwise, Bounded, CheckedAdd, CheckedSub};
2121
use num::{CheckedDiv, Zero, One, strconv};
2222
use num::{ToStrRadix, FromStrRadix};
2323
use option::{Option, Some, None};
@@ -26,7 +26,7 @@ use unstable::intrinsics;
2626

2727
int_module!(i64, 64)
2828

29-
impl BitCount for i64 {
29+
impl Bitwise for i64 {
3030
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
3131
#[inline]
3232
fn population_count(&self) -> i64 { unsafe { intrinsics::ctpop64(*self) } }

src/libstd/num/i8.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
18+
use num::{Bitwise, Bounded, CheckedAdd, CheckedSub, CheckedMul};
1919
use num::{CheckedDiv, Zero, One, strconv};
2020
use num::{ToStrRadix, FromStrRadix};
2121
use option::{Option, Some, None};
@@ -24,7 +24,7 @@ use unstable::intrinsics;
2424

2525
int_module!(i8, 8)
2626

27-
impl BitCount for i8 {
27+
impl Bitwise for i8 {
2828
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
2929
#[inline]
3030
fn population_count(&self) -> i8 { unsafe { intrinsics::ctpop8(*self) } }

src/libstd/num/int.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
18+
use num::{Bitwise, Bounded, CheckedAdd, CheckedSub, CheckedMul};
1919
use num::{CheckedDiv, Zero, One, strconv};
2020
use num::{ToStrRadix, FromStrRadix};
2121
use option::{Option, Some, None};
@@ -26,7 +26,7 @@ use unstable::intrinsics;
2626
#[cfg(target_word_size = "64")] int_module!(int, 64)
2727

2828
#[cfg(target_word_size = "32")]
29-
impl BitCount for int {
29+
impl Bitwise for int {
3030
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
3131
#[inline]
3232
fn population_count(&self) -> int { (*self as i32).population_count() as int }
@@ -41,7 +41,7 @@ impl BitCount for int {
4141
}
4242

4343
#[cfg(target_word_size = "64")]
44-
impl BitCount for int {
44+
impl Bitwise for int {
4545
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
4646
#[inline]
4747
fn population_count(&self) -> int { (*self as i64).population_count() as int }

src/libstd/num/int_macros.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ impl Integer for $T {
315315
fn is_odd(&self) -> bool { !self.is_even() }
316316
}
317317

318-
impl Bitwise for $T {}
319-
320318
#[cfg(not(test))]
321319
impl BitOr<$T,$T> for $T {
322320
#[inline]
@@ -446,6 +444,7 @@ mod tests {
446444
use i32;
447445
use num;
448446
use num::CheckedDiv;
447+
use num::Bitwise;
449448
use mem;
450449

451450
#[test]

src/libstd/num/mod.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,27 @@ pub trait Real: Signed
324324
/// Inverse hyperbolic tangent function.
325325
#[inline(always)] pub fn atanh<T: Real>(value: T) -> T { value.atanh() }
326326

327-
/// Collects the bitwise operators under one trait.
328-
pub trait Bitwise: Not<Self>
327+
pub trait Bounded {
328+
// FIXME (#5527): These should be associated constants
329+
fn min_value() -> Self;
330+
fn max_value() -> Self;
331+
}
332+
333+
/// Numbers with a fixed binary representation.
334+
pub trait Bitwise: Bounded
335+
+ Not<Self>
329336
+ BitAnd<Self,Self>
330337
+ BitOr<Self,Self>
331338
+ BitXor<Self,Self>
332339
+ Shl<Self,Self>
333-
+ Shr<Self,Self> {}
334-
335-
/// A trait for common counting operations on bits.
336-
pub trait BitCount {
340+
+ Shr<Self,Self> {
337341
/// Returns the number of bits set in the number.
338342
///
339343
/// # Example
340344
///
341345
/// ```rust
346+
/// use std::num::Bitwise;
347+
///
342348
/// let n = 0b0101000u16;
343349
/// assert_eq!(n.population_count(), 2);
344350
/// ```
@@ -348,6 +354,8 @@ pub trait BitCount {
348354
/// # Example
349355
///
350356
/// ```rust
357+
/// use std::num::Bitwise;
358+
///
351359
/// let n = 0b0101000u16;
352360
/// assert_eq!(n.leading_zeros(), 10);
353361
/// ```
@@ -357,18 +365,14 @@ pub trait BitCount {
357365
/// # Example
358366
///
359367
/// ```rust
368+
/// use std::num::Bitwise;
369+
///
360370
/// let n = 0b0101000u16;
361371
/// assert_eq!(n.trailing_zeros(), 3);
362372
/// ```
363373
fn trailing_zeros(&self) -> Self;
364374
}
365375

366-
pub trait Bounded {
367-
// FIXME (#5527): These should be associated constants
368-
fn min_value() -> Self;
369-
fn max_value() -> Self;
370-
}
371-
372376
/// Specifies the available operations common to all of Rust's core numeric primitives.
373377
/// These may not always make sense from a purely mathematical point of view, but
374378
/// may be useful for systems programming.
@@ -394,8 +398,7 @@ pub trait Primitive: Clone
394398
/// A collection of traits relevant to primitive signed and unsigned integers
395399
pub trait Int: Integer
396400
+ Primitive
397-
+ Bitwise
398-
+ BitCount {}
401+
+ Bitwise {}
399402

400403
/// Used for representing the classification of floating point numbers
401404
#[deriving(Eq)]

src/libstd/num/u16.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::BitCount;
18+
use num::{Bitwise, Bounded};
1919
use num::{CheckedAdd, CheckedSub, CheckedMul};
2020
use num::{CheckedDiv, Zero, One, strconv};
2121
use num::{ToStrRadix, FromStrRadix};

src/libstd/num/u32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::BitCount;
18+
use num::{Bitwise, Bounded};
1919
use num::{CheckedAdd, CheckedSub, CheckedMul};
2020
use num::{CheckedDiv, Zero, One, strconv};
2121
use num::{ToStrRadix, FromStrRadix};

src/libstd/num/u64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::BitCount;
18+
use num::{Bitwise, Bounded};
1919
#[cfg(target_word_size = "64")]
2020
use num::CheckedMul;
2121
use num::{CheckedAdd, CheckedSub};

src/libstd/num/u8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use prelude::*;
1616

1717
use default::Default;
18-
use num::BitCount;
18+
use num::{Bitwise, Bounded};
1919
use num::{CheckedAdd, CheckedSub, CheckedMul};
2020
use num::{CheckedDiv, Zero, One, strconv};
2121
use num::{ToStrRadix, FromStrRadix};

src/libstd/num/uint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use prelude::*;
1616

1717
use default::Default;
1818
use mem;
19-
use num::BitCount;
19+
use num::{Bitwise, Bounded};
2020
use num::{CheckedAdd, CheckedSub, CheckedMul};
2121
use num::{CheckedDiv, Zero, One, strconv};
2222
use num::{ToStrRadix, FromStrRadix};

src/libstd/num/uint_macros.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ impl Integer for $T {
176176
fn is_odd(&self) -> bool { !self.is_even() }
177177
}
178178

179-
impl Bitwise for $T {}
180-
181179
#[cfg(not(test))]
182180
impl BitOr<$T,$T> for $T {
183181
#[inline]
@@ -298,7 +296,7 @@ impl Primitive for $T {
298296
fn is_signed(_: Option<$T>) -> bool { false }
299297
}
300298

301-
impl BitCount for $T {
299+
impl Bitwise for $T {
302300
/// Counts the number of bits set. Wraps LLVM's `ctpop` intrinsic.
303301
#[inline]
304302
fn population_count(&self) -> $T {
@@ -325,6 +323,7 @@ mod tests {
325323

326324
use num;
327325
use num::CheckedDiv;
326+
use num::Bitwise;
328327
use mem;
329328
use u16;
330329

src/libstd/prelude.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ pub use iter::{FromIterator, Extendable};
5858
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
5959
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
6060
pub use num::Times;
61-
pub use num::{Bitwise, BitCount, Bounded, Integer, Real};
62-
pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
61+
pub use num::{Integer, Real, Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
6362
pub use num::{Orderable, Signed, Unsigned, Round};
6463
pub use num::{Primitive, Int, Float, ToStrRadix, ToPrimitive, FromPrimitive};
6564
pub use path::{GenericPath, Path, PosixPath, WindowsPath};

0 commit comments

Comments
 (0)