diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 4599aff000d..29301bfd6fe 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1123,7 +1123,7 @@ impl Iterator for ElementSwaps { // #[inline] fn next(&mut self) -> Option<(usize, usize)> { fn new_pos_wrapping(i: usize, s: Direction) -> usize { - i.wrapping_add(match s { Pos => 1, Neg => -1 }) + i.wrapping_add(match s { Pos => 1, Neg => !0 /* aka -1 */ }) } fn new_pos(i: usize, s: Direction) -> usize { diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 8c396a4e7fb..d738ff947c4 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -161,7 +161,7 @@ pub enum Ordering { AtomicUsize { v: UnsafeCell { value: 0, } }; // NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly -const UINT_TRUE: usize = -1; +const UINT_TRUE: usize = !0; impl AtomicBool { /// Creates a new `AtomicBool`. diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 906c87f3ffd..76e09eedbdf 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -287,7 +287,7 @@ pub enum BorrowState { // (will not outgrow its range since `usize` is the size of the address space) type BorrowFlag = usize; const UNUSED: BorrowFlag = 0; -const WRITING: BorrowFlag = -1; +const WRITING: BorrowFlag = !0; impl RefCell { /// Creates a new `RefCell` containing `value`. diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index a4829ed96b3..13f168b3fdb 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -517,7 +517,7 @@ fn one() -> $T { 1 } fn min_value() -> $T { 0 } #[inline] - fn max_value() -> $T { -1 } + fn max_value() -> $T { !0 } #[inline] fn count_ones(self) -> u32 { diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 862eb16d0bf..e1a9efd69ad 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -482,8 +482,10 @@ pub trait Neg { fn neg(self) -> Self::Output; } -macro_rules! neg_impl { - ($($t:ty)*) => ($( + + +macro_rules! neg_impl_core { + ($id:ident => $body:expr, $($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] #[allow(unsigned_negation)] impl Neg for $t { @@ -492,14 +494,28 @@ impl Neg for $t { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn neg(self) -> $t { -self } + fn neg(self) -> $t { let $id = self; $body } } forward_ref_unop! { impl Neg, neg for $t } )*) } -neg_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } +macro_rules! neg_impl_numeric { + ($($t:ty)*) => { neg_impl_core!{ x => -x, $($t)*} } +} + +macro_rules! neg_impl_unsigned { + ($($t:ty)*) => { + neg_impl_core!{ x => { + #[cfg(stage0)] + use ::num::wrapping::WrappingOps; + !x.wrapping_add(1) + }, $($t)*} } +} + +neg_impl_unsigned! { usize u8 u16 u32 u64 } +neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 } /// The `Not` trait is used to specify the functionality of unary `!`. /// diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 934c4515614..c78fa803361 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -873,7 +873,7 @@ fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool) #[allow(dead_code)] #[allow(deprecated)] fn maximal_suffix(arr: &[u8], reversed: bool) -> (usize, usize) { - let mut left: usize = -1; // Corresponds to i in the paper + let mut left: usize = !0; // Corresponds to i in the paper let mut right = 0; // Corresponds to j in the paper let mut offset = 1; // Corresponds to k in the paper let mut period = 1; // Corresponds to p in the paper diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index b7162c4a177..77e18be298b 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -4696,7 +4696,7 @@ pub mod posix88 { pub const MAP_FIXED : c_int = 0x0010; pub const MAP_ANON : c_int = 0x1000; - pub const MAP_FAILED : *mut c_void = -1 as *mut c_void; + pub const MAP_FAILED : *mut c_void = !0 as *mut c_void; pub const MCL_CURRENT : c_int = 0x0001; pub const MCL_FUTURE : c_int = 0x0002; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 696c7960c3e..7ea77a79619 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -117,7 +117,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { use libc; use libc::funcs::posix01::signal::signal; unsafe { - assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != -1); + assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0); } } ignore_sigpipe();