diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/cell.rs | 6 | ||||
| -rw-r--r-- | src/libcore/num/mod.rs | 9 | ||||
| -rw-r--r-- | src/test/run-pass/const-int-sign.rs | 14 | ||||
| -rw-r--r-- | src/test/run-pass/rfcs/rfc-1789-as-cell/from-mut.rs | 1 |
4 files changed, 17 insertions, 13 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 239ff017cc2..beafddc5a10 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -494,7 +494,6 @@ impl<T: ?Sized> Cell<T> { /// # Examples /// /// ``` - /// #![feature(as_cell)] /// use std::cell::Cell; /// /// let slice: &mut [i32] = &mut [1, 2, 3]; @@ -504,7 +503,7 @@ impl<T: ?Sized> Cell<T> { /// assert_eq!(slice_cell.len(), 3); /// ``` #[inline] - #[unstable(feature = "as_cell", issue="43038")] + #[stable(feature = "as_cell", since = "1.37.0")] pub fn from_mut(t: &mut T) -> &Cell<T> { unsafe { &*(t as *mut T as *const Cell<T>) @@ -541,7 +540,6 @@ impl<T> Cell<[T]> { /// # Examples /// /// ``` - /// #![feature(as_cell)] /// use std::cell::Cell; /// /// let slice: &mut [i32] = &mut [1, 2, 3]; @@ -550,7 +548,7 @@ impl<T> Cell<[T]> { /// /// assert_eq!(slice_cell.len(), 3); /// ``` - #[unstable(feature = "as_cell", issue="43038")] + #[stable(feature = "as_cell", since = "1.37.0")] pub fn as_slice_of_cells(&self) -> &[Cell<T>] { unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index dd7090623f5..304b2fc9ebb 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1993,13 +1993,10 @@ assert_eq!((-10", stringify!($SelfT), ").signum(), -1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_sign")] #[inline] - pub fn signum(self) -> Self { - match self { - n if n > 0 => 1, - 0 => 0, - _ => -1, - } + pub const fn signum(self) -> Self { + (self > 0) as Self - (self < 0) as Self } } diff --git a/src/test/run-pass/const-int-sign.rs b/src/test/run-pass/const-int-sign.rs index 9d656a02030..fcd3ef4ea02 100644 --- a/src/test/run-pass/const-int-sign.rs +++ b/src/test/run-pass/const-int-sign.rs @@ -1,11 +1,21 @@ +#![feature(const_int_sign)] + const NEGATIVE_A: bool = (-10i32).is_negative(); const NEGATIVE_B: bool = 10i32.is_negative(); -const POSITIVE_A: bool= (-10i32).is_positive(); -const POSITIVE_B: bool= 10i32.is_positive(); +const POSITIVE_A: bool = (-10i32).is_positive(); +const POSITIVE_B: bool = 10i32.is_positive(); + +const SIGNUM_POS: i32 = 10i32.signum(); +const SIGNUM_NIL: i32 = 0i32.signum(); +const SIGNUM_NEG: i32 = (-42i32).signum(); fn main() { assert!(NEGATIVE_A); assert!(!NEGATIVE_B); assert!(!POSITIVE_A); assert!(POSITIVE_B); + + assert_eq!(SIGNUM_POS, 1); + assert_eq!(SIGNUM_NIL, 0); + assert_eq!(SIGNUM_NEG, -1); } diff --git a/src/test/run-pass/rfcs/rfc-1789-as-cell/from-mut.rs b/src/test/run-pass/rfcs/rfc-1789-as-cell/from-mut.rs index f275c67fdf0..ea3ad7aed49 100644 --- a/src/test/run-pass/rfcs/rfc-1789-as-cell/from-mut.rs +++ b/src/test/run-pass/rfcs/rfc-1789-as-cell/from-mut.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(as_cell)] use std::cell::Cell; |
