Skip to content

Commit 3225b04

Browse files
committed
fallout from feature-gating unary negation on unsigned integers.
1 parent d8e3093 commit 3225b04

File tree

8 files changed

+27
-11
lines changed

8 files changed

+27
-11
lines changed

src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl Iterator for ElementSwaps {
11231123
// #[inline]
11241124
fn next(&mut self) -> Option<(usize, usize)> {
11251125
fn new_pos_wrapping(i: usize, s: Direction) -> usize {
1126-
i.wrapping_add(match s { Pos => 1, Neg => -1 })
1126+
i.wrapping_add(match s { Pos => 1, Neg => !0 /* aka -1 */ })
11271127
}
11281128

11291129
fn new_pos(i: usize, s: Direction) -> usize {

src/libcore/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub const ATOMIC_USIZE_INIT: AtomicUsize =
161161
AtomicUsize { v: UnsafeCell { value: 0, } };
162162

163163
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
164-
const UINT_TRUE: usize = -1;
164+
const UINT_TRUE: usize = !0;
165165

166166
impl AtomicBool {
167167
/// Creates a new `AtomicBool`.

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub enum BorrowState {
287287
// (will not outgrow its range since `usize` is the size of the address space)
288288
type BorrowFlag = usize;
289289
const UNUSED: BorrowFlag = 0;
290-
const WRITING: BorrowFlag = -1;
290+
const WRITING: BorrowFlag = !0;
291291

292292
impl<T> RefCell<T> {
293293
/// Creates a new `RefCell` containing `value`.

src/libcore/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ macro_rules! uint_impl {
517517
fn min_value() -> $T { 0 }
518518

519519
#[inline]
520-
fn max_value() -> $T { -1 }
520+
fn max_value() -> $T { !0 }
521521

522522
#[inline]
523523
fn count_ones(self) -> u32 {

src/libcore/ops.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,10 @@ pub trait Neg {
482482
fn neg(self) -> Self::Output;
483483
}
484484

485-
macro_rules! neg_impl {
486-
($($t:ty)*) => ($(
485+
486+
487+
macro_rules! neg_impl_core {
488+
($id:ident => $body:expr, $($t:ty)*) => ($(
487489
#[stable(feature = "rust1", since = "1.0.0")]
488490
#[allow(unsigned_negation)]
489491
impl Neg for $t {
@@ -492,14 +494,28 @@ macro_rules! neg_impl {
492494

493495
#[inline]
494496
#[stable(feature = "rust1", since = "1.0.0")]
495-
fn neg(self) -> $t { -self }
497+
fn neg(self) -> $t { let $id = self; $body }
496498
}
497499

498500
forward_ref_unop! { impl Neg, neg for $t }
499501
)*)
500502
}
501503

502-
neg_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
504+
macro_rules! neg_impl_numeric {
505+
($($t:ty)*) => { neg_impl_core!{ x => -x, $($t)*} }
506+
}
507+
508+
macro_rules! neg_impl_unsigned {
509+
($($t:ty)*) => {
510+
neg_impl_core!{ x => {
511+
#[cfg(stage0)]
512+
use ::num::wrapping::WrappingOps;
513+
!x.wrapping_add(1)
514+
}, $($t)*} }
515+
}
516+
517+
neg_impl_unsigned! { usize u8 u16 u32 u64 }
518+
neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 }
503519

504520
/// The `Not` trait is used to specify the functionality of unary `!`.
505521
///

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ impl TwoWaySearcher {
873873
#[allow(dead_code)]
874874
#[allow(deprecated)]
875875
fn maximal_suffix(arr: &[u8], reversed: bool) -> (usize, usize) {
876-
let mut left: usize = -1; // Corresponds to i in the paper
876+
let mut left: usize = !0; // Corresponds to i in the paper
877877
let mut right = 0; // Corresponds to j in the paper
878878
let mut offset = 1; // Corresponds to k in the paper
879879
let mut period = 1; // Corresponds to p in the paper

src/liblibc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4696,7 +4696,7 @@ pub mod consts {
46964696
pub const MAP_FIXED : c_int = 0x0010;
46974697
pub const MAP_ANON : c_int = 0x1000;
46984698

4699-
pub const MAP_FAILED : *mut c_void = -1 as *mut c_void;
4699+
pub const MAP_FAILED : *mut c_void = !0 as *mut c_void;
47004700

47014701
pub const MCL_CURRENT : c_int = 0x0001;
47024702
pub const MCL_FUTURE : c_int = 0x0002;

src/libstd/rt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
117117
use libc;
118118
use libc::funcs::posix01::signal::signal;
119119
unsafe {
120-
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != -1);
120+
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0);
121121
}
122122
}
123123
ignore_sigpipe();

0 commit comments

Comments
 (0)