diff options
Diffstat (limited to 'src/libcore')
36 files changed, 500 insertions, 182 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 5c24e3d8f5d..cb476acfb3a 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -100,6 +100,7 @@ impl Layout { /// This function is unsafe as it does not verify the preconditions from /// [`Layout::from_size_align`](#method.from_size_align). #[stable(feature = "alloc_layout", since = "1.28.0")] + #[rustc_const_stable(feature = "alloc_layout", since = "1.28.0")] #[inline] pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self { Layout { size_: size, align_: NonZeroUsize::new_unchecked(align) } diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 466750fc7d2..882c4a53faf 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -423,13 +423,9 @@ impl TypeId { /// assert_eq!(is_string(&"cookie monster".to_string()), true); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature="const_type_id")] + #[rustc_const_unstable(feature="const_type_id", issue = "41875")] pub const fn of<T: ?Sized + 'static>() -> TypeId { TypeId { - #[cfg(bootstrap)] - // SAFETY: going away soon - t: unsafe { intrinsics::type_id::<T>() }, - #[cfg(not(bootstrap))] t: intrinsics::type_id::<T>(), } } @@ -461,7 +457,7 @@ impl TypeId { /// ); /// ``` #[stable(feature = "type_name", since = "1.38.0")] -#[rustc_const_unstable(feature = "const_type_name")] +#[rustc_const_unstable(feature = "const_type_name", issue = "63084")] pub const fn type_name<T: ?Sized>() -> &'static str { intrinsics::type_name::<T>() } @@ -474,7 +470,7 @@ pub const fn type_name<T: ?Sized>() -> &'static str { /// /// This is intended for diagnostic use. The exact contents and format of the /// string are not specified, other than being a best-effort description of the -/// type. For example, `type_name_of::<Option<String>>(None)` could return the +/// type. For example, `type_name_of::<Option<String>>(None)` could return /// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not /// `"foobar"`. In addition, the output may change between versions of the /// compiler. @@ -499,7 +495,7 @@ pub const fn type_name<T: ?Sized>() -> &'static str { /// println!("{}", type_name_of_val(&y)); /// ``` #[unstable(feature = "type_name_of_val", issue = "66359")] -#[rustc_const_unstable(feature = "const_type_name")] +#[rustc_const_unstable(feature = "const_type_name", issue = "63084")] pub const fn type_name_of_val<T: ?Sized>(val: &T) -> &'static str { let _ = val; type_name::<T>() diff --git a/src/libcore/benches/lib.rs b/src/libcore/benches/lib.rs index 6932c7fe221..570fc4ab933 100644 --- a/src/libcore/benches/lib.rs +++ b/src/libcore/benches/lib.rs @@ -11,4 +11,5 @@ mod hash; mod iter; mod num; mod ops; +mod pattern; mod slice; diff --git a/src/libcore/benches/pattern.rs b/src/libcore/benches/pattern.rs new file mode 100644 index 00000000000..a49490cec12 --- /dev/null +++ b/src/libcore/benches/pattern.rs @@ -0,0 +1,43 @@ +use test::black_box; +use test::Bencher; + +#[bench] +fn starts_with_char(b: &mut Bencher) { + let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind"); + b.iter(|| { + for _ in 0..1024 { + black_box(text.starts_with('k')); + } + }) +} + +#[bench] +fn starts_with_str(b: &mut Bencher) { + let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind"); + b.iter(|| { + for _ in 0..1024 { + black_box(text.starts_with("k")); + } + }) +} + + +#[bench] +fn ends_with_char(b: &mut Bencher) { + let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind"); + b.iter(|| { + for _ in 0..1024 { + black_box(text.ends_with('k')); + } + }) +} + +#[bench] +fn ends_with_str(b: &mut Bencher) { + let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind"); + b.iter(|| { + for _ in 0..1024 { + black_box(text.ends_with("k")); + } + }) +} diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 03f32e72618..099e5307f64 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -324,6 +324,7 @@ impl<T> Cell<T> { /// let c = Cell::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_cell_new", since = "1.32.0")] #[inline] pub const fn new(value: T) -> Cell<T> { Cell { @@ -469,6 +470,7 @@ impl<T: ?Sized> Cell<T> { /// ``` #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] + #[rustc_const_stable(feature = "const_cell_as_ptr", since = "1.32.0")] pub const fn as_ptr(&self) -> *mut T { self.value.get() } @@ -649,6 +651,7 @@ impl<T> RefCell<T> { /// let c = RefCell::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_refcell_new", since = "1.32.0")] #[inline] pub const fn new(value: T) -> RefCell<T> { RefCell { @@ -1501,6 +1504,7 @@ impl<T> UnsafeCell<T> { /// let uc = UnsafeCell::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")] #[inline] pub const fn new(value: T) -> UnsafeCell<T> { UnsafeCell { value } @@ -1543,6 +1547,7 @@ impl<T: ?Sized> UnsafeCell<T> { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")] pub const fn get(&self) -> *mut T { // We can just cast the pointer from `UnsafeCell<T>` to `T` because of // #[repr(transparent)]. This exploits libstd's special status, there is diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 5c63eebf595..bb6d6db57d2 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -911,6 +911,7 @@ impl char { /// assert!(!non_ascii.is_ascii()); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.32.0")] #[inline] pub const fn is_ascii(&self) -> bool { *self as u32 <= 0x7F diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 6e7a46ba62a..18f808638de 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -195,7 +195,7 @@ mod impls { bool char } - #[stable(feature = "never_type", since = "1.41.0")] + #[unstable(feature = "never_type", issue = "35121")] impl Clone for ! { #[inline] fn clone(&self) -> Self { diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index fd4be02e20f..4aa52a7a390 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -1141,24 +1141,24 @@ mod impls { ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } - #[stable(feature = "never_type", since = "1.41.0")] + #[unstable(feature = "never_type", issue = "35121")] impl PartialEq for ! { fn eq(&self, _: &!) -> bool { *self } } - #[stable(feature = "never_type", since = "1.41.0")] + #[unstable(feature = "never_type", issue = "35121")] impl Eq for ! {} - #[stable(feature = "never_type", since = "1.41.0")] + #[unstable(feature = "never_type", issue = "35121")] impl PartialOrd for ! { fn partial_cmp(&self, _: &!) -> Option<Ordering> { *self } } - #[stable(feature = "never_type", since = "1.41.0")] + #[unstable(feature = "never_type", issue = "35121")] impl Ord for ! { fn cmp(&self, _: &!) -> Ordering { *self diff --git a/src/libcore/convert/mod.rs b/src/libcore/convert/mod.rs index 5414d9ac234..959fd63df51 100644 --- a/src/libcore/convert/mod.rs +++ b/src/libcore/convert/mod.rs @@ -40,6 +40,8 @@ #![stable(feature = "rust1", since = "1.0.0")] +use crate::fmt; + mod num; #[unstable(feature = "convert_float_to_int", issue = "67057")] @@ -99,6 +101,7 @@ pub use num::FloatToInt; /// assert_eq!(vec![1, 3], filtered); /// ``` #[stable(feature = "convert_id", since = "1.33.0")] +#[rustc_const_stable(feature = "const_identity", since = "1.33.0")] #[inline] pub const fn identity<T>(x: T) -> T { x @@ -291,7 +294,7 @@ pub trait Into<T>: Sized { /// [`Into`]. /// /// One should always prefer implementing `From` over [`Into`] -/// because implementing `From` automatically provides one with a implementation of [`Into`] +/// because implementing `From` automatically provides one with an implementation of [`Into`] /// thanks to the blanket implementation in the standard library. /// /// Only implement [`Into`] if a conversion to a type outside the current crate is required. @@ -429,7 +432,9 @@ pub trait TryInto<T>: Sized { /// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T` /// - [`try_from`] is reflexive, which means that `TryFrom<T> for T` /// is implemented and cannot fail -- the associated `Error` type for -/// calling `T::try_from()` on a value of type `T` is [`!`]. +/// calling `T::try_from()` on a value of type `T` is [`Infallible`]. +/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be +/// equivalent. /// /// `TryFrom<T>` can be implemented as follows: /// @@ -478,6 +483,7 @@ pub trait TryInto<T>: Sized { /// [`TryInto`]: trait.TryInto.html /// [`i32::MAX`]: ../../std/i32/constant.MAX.html /// [`!`]: ../../std/primitive.never.html +/// [`Infallible`]: enum.Infallible.html #[stable(feature = "try_from", since = "1.34.0")] pub trait TryFrom<T>: Sized { /// The type returned in the event of a conversion error. @@ -633,9 +639,9 @@ impl AsRef<str> for str { // THE NO-ERROR ERROR TYPE //////////////////////////////////////////////////////////////////////////////// -/// A type alias for [the `!` “never” type][never]. +/// The error type for errors that can never happen. /// -/// `Infallible` represents types of errors that can never happen since `!` has no valid values. +/// Since this enum has no variant, a value of this type can never actually exist. /// This can be useful for generic APIs that use [`Result`] and parameterize the error type, /// to indicate that the result is always [`Ok`]. /// @@ -652,10 +658,33 @@ impl AsRef<str> for str { /// } /// ``` /// -/// # Eventual deprecation +/// # Future compatibility +/// +/// This enum has the same role as [the `!` “never” type][never], +/// which is unstable in this version of Rust. +/// When `!` is stabilized, we plan to make `Infallible` a type alias to it: +/// +/// ```ignore (illustrates future std change) +/// pub type Infallible = !; +/// ``` +/// +/// … and eventually deprecate `Infallible`. +/// +/// +/// However there is one case where `!` syntax can be used +/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type. +/// Specifically, it is possible implementations for two different function pointer types: +/// +/// ``` +/// trait MyTrait {} +/// impl MyTrait for fn() -> ! {} +/// impl MyTrait for fn() -> std::convert::Infallible {} +/// ``` /// -/// Previously, `Infallible` was defined as `enum Infallible {}`. -/// Now that it is merely a type alias to `!`, we will eventually deprecate `Infallible`. +/// With `Infallible` being an enum, this code is valid. +/// However when `Infallible` becomes an alias for the never type, +/// the two `impl`s will start to overlap +/// and therefore will be disallowed by the language’s trait coherence rules. /// /// [`Ok`]: ../result/enum.Result.html#variant.Ok /// [`Result`]: ../result/enum.Result.html @@ -663,4 +692,57 @@ impl AsRef<str> for str { /// [`Into`]: trait.Into.html /// [never]: ../../std/primitive.never.html #[stable(feature = "convert_infallible", since = "1.34.0")] -pub type Infallible = !; +#[derive(Copy)] +pub enum Infallible {} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl Clone for Infallible { + fn clone(&self) -> Infallible { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl fmt::Debug for Infallible { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl fmt::Display for Infallible { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl PartialEq for Infallible { + fn eq(&self, _: &Infallible) -> bool { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl Eq for Infallible {} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl PartialOrd for Infallible { + fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl Ord for Infallible { + fn cmp(&self, _other: &Self) -> crate::cmp::Ordering { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl From<!> for Infallible { + fn from(x: !) -> Self { + x + } +} diff --git a/src/libcore/convert/num.rs b/src/libcore/convert/num.rs index 6f5ee756f58..596da6f786b 100644 --- a/src/libcore/convert/num.rs +++ b/src/libcore/convert/num.rs @@ -13,7 +13,6 @@ mod private { /// Typically doesn’t need to be used directly. #[unstable(feature = "convert_float_to_int", issue = "67057")] pub trait FloatToInt<Int>: private::Sealed + Sized { - #[cfg(not(bootstrap))] #[unstable(feature = "float_approx_unchecked_to", issue = "67058")] #[doc(hidden)] unsafe fn approx_unchecked(self) -> Int; @@ -26,7 +25,6 @@ macro_rules! impl_float_to_int { $( #[unstable(feature = "convert_float_to_int", issue = "67057")] impl FloatToInt<$Int> for $Float { - #[cfg(not(bootstrap))] #[doc(hidden)] #[inline] unsafe fn approx_unchecked(self) -> $Int { diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index e2f49ee25a7..793c1f124ed 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -63,7 +63,7 @@ pub mod rt { /// /// let pythagorean_triple = Triangle { a: 3.0, b: 4.0, c: 5.0 }; /// -/// println!("{}", pythagorean_triple); +/// assert_eq!(format!("{}", pythagorean_triple), "(3, 4, 5)"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub type Result = result::Result<(), Error>; @@ -440,7 +440,7 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {:?}", origin); +/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }"); /// ``` /// /// Manually implementing: @@ -455,28 +455,25 @@ impl Display for Arguments<'_> { /// /// impl fmt::Debug for Point { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -/// write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y) +/// f.debug_struct("Point") +/// .field("x", &self.x) +/// .field("y", &self.y) +/// .finish() /// } /// } /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {:?}", origin); +/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }"); /// ``` /// -/// This outputs: -/// -/// ```text -/// The origin is: Point { x: 0, y: 0 } -/// ``` -/// -/// There are a number of `debug_*` methods on [`Formatter`] to help you with manual -/// implementations, such as [`debug_struct`][debug_struct]. +/// There are a number of helper methods on the [`Formatter`] struct to help you with manual +/// implementations, such as [`debug_struct`]. /// /// `Debug` implementations using either `derive` or the debug builder API /// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`. /// -/// [debug_struct]: ../../std/fmt/struct.Formatter.html#method.debug_struct +/// [`debug_struct`]: ../../std/fmt/struct.Formatter.html#method.debug_struct /// [`Formatter`]: ../../std/fmt/struct.Formatter.html /// /// Pretty-printing with `#?`: @@ -490,17 +487,13 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {:#?}", origin); -/// ``` -/// -/// This outputs: -/// -/// ```text -/// The origin is: Point { +/// assert_eq!(format!("The origin is: {:#?}", origin), +/// "The origin is: Point { /// x: 0, -/// y: 0 -/// } +/// y: 0, +/// }"); /// ``` + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented( on( @@ -528,12 +521,20 @@ pub trait Debug { /// /// impl fmt::Debug for Position { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "({:?}, {:?})", self.longitude, self.latitude) + /// f.debug_tuple("") + /// .field(&self.longitude) + /// .field(&self.latitude) + /// .finish() /// } /// } /// - /// assert_eq!("(1.987, 2.983)".to_owned(), - /// format!("{:?}", Position { longitude: 1.987, latitude: 2.983, })); + /// let position = Position { longitude: 1.987, latitude: 2.983 }; + /// assert_eq!(format!("{:?}", position), "(1.987, 2.983)"); + /// + /// assert_eq!(format!("{:#?}", position), "( + /// 1.987, + /// 2.983, + /// )"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, f: &mut Formatter<'_>) -> Result; @@ -584,7 +585,7 @@ pub use macros::Debug; /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {}", origin); +/// assert_eq!(format!("The origin is: {}", origin), "The origin is: (0, 0)"); /// ``` #[rustc_on_unimplemented( on( @@ -618,7 +619,7 @@ pub trait Display { /// } /// } /// - /// assert_eq!("(1.987, 2.983)".to_owned(), + /// assert_eq!("(1.987, 2.983)", /// format!("{}", Position { longitude: 1.987, latitude: 2.983, })); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -668,7 +669,9 @@ pub trait Display { /// /// let l = Length(9); /// -/// println!("l as octal is: {:o}", l); +/// assert_eq!(format!("l as octal is: {:o}", l), "l as octal is: 11"); +/// +/// assert_eq!(format!("l as octal is: {:#06o}", l), "l as octal is: 0o0011"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Octal { @@ -718,7 +721,12 @@ pub trait Octal { /// /// let l = Length(107); /// -/// println!("l as binary is: {:b}", l); +/// assert_eq!(format!("l as binary is: {:b}", l), "l as binary is: 1101011"); +/// +/// assert_eq!( +/// format!("l as binary is: {:#032b}", l), +/// "l as binary is: 0b000000000000000000000001101011" +/// ); /// ``` /// /// [module]: ../../std/fmt/index.html @@ -777,7 +785,9 @@ pub trait Binary { /// /// let l = Length(9); /// -/// println!("l as hex is: {:x}", l); +/// assert_eq!(format!("l as hex is: {:x}", l), "l as hex is: 9"); +/// +/// assert_eq!(format!("l as hex is: {:#010x}", l), "l as hex is: 0x00000009"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerHex { @@ -828,9 +838,11 @@ pub trait LowerHex { /// } /// } /// -/// let l = Length(9); +/// let l = Length(i32::max_value()); /// -/// println!("l as hex is: {:X}", l); +/// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF"); +/// +/// assert_eq!(format!("l as hex is: {:#010X}", l), "l as hex is: 0x7FFFFFFF"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperHex { @@ -877,6 +889,10 @@ pub trait UpperHex { /// let l = Length(42); /// /// println!("l is in memory here: {:p}", l); +/// +/// let l_ptr = format!("{:018p}", l); +/// assert_eq!(l_ptr.len(), 18); +/// assert_eq!(&l_ptr[..2], "0x"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Pointer { @@ -912,14 +928,22 @@ pub trait Pointer { /// /// impl fmt::LowerExp for Length { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -/// let val = self.0; -/// write!(f, "{}e1", val / 10) +/// let val = f64::from(self.0); +/// fmt::LowerExp::fmt(&val, f) // delegate to f64's implementation /// } /// } /// /// let l = Length(100); /// -/// println!("l in scientific notation is: {:e}", l); +/// assert_eq!( +/// format!("l in scientific notation is: {:e}", l), +/// "l in scientific notation is: 1e2" +/// ); +/// +/// assert_eq!( +/// format!("l in scientific notation is: {:05e}", l), +/// "l in scientific notation is: 001e2" +/// ); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerExp { @@ -955,14 +979,22 @@ pub trait LowerExp { /// /// impl fmt::UpperExp for Length { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -/// let val = self.0; -/// write!(f, "{}E1", val / 10) +/// let val = f64::from(self.0); +/// fmt::UpperExp::fmt(&val, f) // delegate to f64's implementation /// } /// } /// /// let l = Length(100); /// -/// println!("l in scientific notation is: {:E}", l); +/// assert_eq!( +/// format!("l in scientific notation is: {:E}", l), +/// "l in scientific notation is: 1E2" +/// ); +/// +/// assert_eq!( +/// format!("l in scientific notation is: {:05E}", l), +/// "l in scientific notation is: 001E2" +/// ); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperExp { @@ -1807,8 +1839,7 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// // prints "[10, 11]" - /// println!("{:?}", Foo(vec![10, 11])); + /// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "[10, 11]"); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> { @@ -1831,8 +1862,7 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// // prints "{10, 11}" - /// println!("{:?}", Foo(vec![10, 11])); + /// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "{10, 11}"); /// ``` /// /// [`format_args!`]: ../../std/macro.format_args.html @@ -1890,8 +1920,10 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// // prints "{"A": 10, "B": 11}" - /// println!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])); + /// assert_eq!( + /// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])), + /// r#"{"A": 10, "B": 11}"# + /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] pub fn debug_map<'b>(&'b mut self) -> DebugMap<'b, 'a> { @@ -1940,14 +1972,14 @@ macro_rules! fmt_refs { fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp } -#[stable(feature = "never_type", since = "1.41.0")] +#[unstable(feature = "never_type", issue = "35121")] impl Debug for ! { fn fmt(&self, _: &mut Formatter<'_>) -> Result { *self } } -#[stable(feature = "never_type", since = "1.41.0")] +#[unstable(feature = "never_type", issue = "35121")] impl Display for ! { fn fmt(&self, _: &mut Formatter<'_>) -> Result { *self diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 18aae59573d..b02acce2d00 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -939,7 +939,7 @@ extern "rust-intrinsic" { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_transmute")] + #[rustc_const_unstable(feature = "const_transmute", issue = "53605")] pub fn transmute<T, U>(e: T) -> U; /// Returns `true` if the actual type given as `T` requires drop @@ -1146,7 +1146,6 @@ extern "rust-intrinsic" { /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range /// https://github.com/rust-lang/rust/issues/10184 - #[cfg(not(bootstrap))] pub fn float_to_int_approx_unchecked<Float, Int>(value: Float) -> Int; @@ -1357,7 +1356,6 @@ extern "rust-intrinsic" { /// Compiles to a NOP during non-Miri codegen. /// /// Perma-unstable: do not use - #[cfg(not(bootstrap))] pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> (); } diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index 39d571006e6..019a3290f01 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -517,14 +517,6 @@ impl<I> Iterator for StepBy<I> where I: Iterator { // overflow handling loop { let mul = n.checked_mul(step); - #[cfg(bootstrap)] - { - // SAFETY: going away soon - if unsafe { intrinsics::likely(mul.is_some()) } { - return self.iter.nth(mul.unwrap() - 1); - } - } - #[cfg(not(bootstrap))] { if intrinsics::likely(mul.is_some()) { return self.iter.nth(mul.unwrap() - 1); diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index ffac7d4e995..a65d47cc2c1 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -281,6 +281,7 @@ impl<T> Default for Empty<T> { /// assert_eq!(None, nope.next()); /// ``` #[stable(feature = "iter_empty", since = "1.2.0")] +#[rustc_const_stable(feature = "const_iter_empty", since = "1.32.0")] pub const fn empty<T>() -> Empty<T> { Empty(marker::PhantomData) } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 8a514f1e78e..a2ab85e64ba 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -74,8 +74,8 @@ #![feature(const_fn)] #![feature(const_fn_union)] #![feature(const_generics)] -#![cfg_attr(not(bootstrap), feature(const_ptr_offset_from))] -#![cfg_attr(not(bootstrap), feature(const_type_name))] +#![feature(const_ptr_offset_from)] +#![feature(const_type_name)] #![feature(custom_inner_attributes)] #![feature(decl_macro)] #![feature(doc_cfg)] @@ -87,22 +87,20 @@ #![feature(iter_once_with)] #![feature(lang_items)] #![feature(link_llvm_intrinsics)] -#![cfg_attr(bootstrap, feature(never_type))] +#![feature(never_type)] #![feature(nll)] #![feature(exhaustive_patterns)] #![feature(no_core)] -#![cfg_attr(bootstrap, feature(on_unimplemented))] #![feature(optin_builtin_traits)] #![feature(prelude_import)] #![feature(repr_simd, platform_intrinsics)] #![feature(rustc_attrs)] -#![feature(rustc_const_unstable)] #![feature(simd_ffi)] #![feature(specialization)] #![feature(staged_api)] #![feature(std_internals)] #![feature(stmt_expr_attributes)] -#![cfg_attr(not(bootstrap), feature(track_caller))] +#![feature(track_caller)] #![feature(transparent_unions)] #![feature(unboxed_closures)] #![feature(unsized_locals)] diff --git a/src/libcore/macros/mod.rs b/src/libcore/macros/mod.rs index cf460745ffa..dd06da7a6d2 100644 --- a/src/libcore/macros/mod.rs +++ b/src/libcore/macros/mod.rs @@ -686,7 +686,7 @@ macro_rules! unimplemented { /// } /// ``` #[macro_export] -#[stable(feature = "todo_macro", since = "1.39.0")] +#[stable(feature = "todo_macro", since = "1.40.0")] macro_rules! todo { () => (panic!("not yet implemented")); ($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+))); diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 288017b7ca5..1b586c3e5fe 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -97,7 +97,7 @@ pub trait Sized { /// Types that can be "unsized" to a dynamically-sized type. /// /// For example, the sized array type `[i8; 2]` implements `Unsize<[i8]>` and -/// `Unsize<fmt::Debug>`. +/// `Unsize<dyn fmt::Debug>`. /// /// All implementations of `Unsize` are provided automatically by the compiler. /// @@ -776,7 +776,7 @@ mod copy_impls { bool char } - #[stable(feature = "never_type", since = "1.41.0")] + #[unstable(feature = "never_type", issue = "35121")] impl Copy for ! {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/mem/manually_drop.rs b/src/libcore/mem/manually_drop.rs index 34fc0618ea2..af4635f89f6 100644 --- a/src/libcore/mem/manually_drop.rs +++ b/src/libcore/mem/manually_drop.rs @@ -63,6 +63,7 @@ impl<T> ManuallyDrop<T> { /// ManuallyDrop::new(Box::new(())); /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] + #[rustc_const_stable(feature = "const_manually_drop", since = "1.36.0")] #[inline(always)] pub const fn new(value: T) -> ManuallyDrop<T> { ManuallyDrop { value } @@ -80,6 +81,7 @@ impl<T> ManuallyDrop<T> { /// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`. /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] + #[rustc_const_stable(feature = "const_manually_drop", since = "1.36.0")] #[inline(always)] pub const fn into_inner(slot: ManuallyDrop<T>) -> T { slot.value diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index 6661df2ae0d..7f80f61aaf9 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -250,6 +250,7 @@ impl<T> MaybeUninit<T> { /// /// [`assume_init`]: #method.assume_init #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0")] #[inline(always)] pub const fn new(val: T) -> MaybeUninit<T> { MaybeUninit { value: ManuallyDrop::new(val) } @@ -264,8 +265,9 @@ impl<T> MaybeUninit<T> { /// /// [type]: union.MaybeUninit.html #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0")] #[inline(always)] - #[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_uninit")] + #[rustc_diagnostic_item = "maybe_uninit_uninit"] pub const fn uninit() -> MaybeUninit<T> { MaybeUninit { uninit: () } } @@ -349,7 +351,7 @@ impl<T> MaybeUninit<T> { /// ``` #[stable(feature = "maybe_uninit", since = "1.36.0")] #[inline] - #[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_zeroed")] + #[rustc_diagnostic_item = "maybe_uninit_zeroed"] pub fn zeroed() -> MaybeUninit<T> { let mut u = MaybeUninit::<T>::uninit(); unsafe { @@ -490,7 +492,7 @@ impl<T> MaybeUninit<T> { /// ``` #[stable(feature = "maybe_uninit", since = "1.36.0")] #[inline(always)] - #[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "assume_init")] + #[rustc_diagnostic_item = "assume_init"] pub unsafe fn assume_init(self) -> T { intrinsics::panic_if_uninhabited::<T>(); ManuallyDrop::into_inner(self.value) diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index bba441464ff..4e8ba8131f7 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -271,6 +271,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[rustc_const_stable(feature = "const_size_of", since = "1.32.0")] pub const fn size_of<T>() -> usize { intrinsics::size_of::<T>() } @@ -298,10 +299,6 @@ pub const fn size_of<T>() -> usize { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn size_of_val<T: ?Sized>(val: &T) -> usize { - #[cfg(bootstrap)] - // SAFETY: going away soon - unsafe { intrinsics::size_of_val(val) } - #[cfg(not(bootstrap))] intrinsics::size_of_val(val) } @@ -346,10 +343,6 @@ pub fn min_align_of<T>() -> usize { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(reason = "use `align_of_val` instead", since = "1.2.0")] pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize { - #[cfg(bootstrap)] - // SAFETY: going away soon - unsafe { intrinsics::min_align_of_val(val) } - #[cfg(not(bootstrap))] intrinsics::min_align_of_val(val) } @@ -371,6 +364,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[rustc_const_stable(feature = "const_align_of", since = "1.32.0")] pub const fn align_of<T>() -> usize { intrinsics::min_align_of::<T>() } @@ -453,6 +447,7 @@ pub fn align_of_val<T: ?Sized>(val: &T) -> usize { /// ``` #[inline] #[stable(feature = "needs_drop", since = "1.21.0")] +#[rustc_const_stable(feature = "const_needs_drop", since = "1.36.0")] pub const fn needs_drop<T>() -> bool { intrinsics::needs_drop::<T>() } @@ -498,7 +493,7 @@ pub const fn needs_drop<T>() -> bool { #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated_in_future)] #[allow(deprecated)] -#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "mem_zeroed")] +#[rustc_diagnostic_item = "mem_zeroed"] pub unsafe fn zeroed<T>() -> T { intrinsics::panic_if_uninhabited::<T>(); intrinsics::init() @@ -510,7 +505,9 @@ pub unsafe fn zeroed<T>() -> T { /// **This function is deprecated.** Use [`MaybeUninit<T>`] instead. /// /// The reason for deprecation is that the function basically cannot be used -/// correctly: [the Rust compiler assumes][inv] that values are properly initialized. +/// correctly: it has the same effect as [`MaybeUninit::uninit().assume_init()`][uninit]. +/// As the [`assume_init` documentation][assume_init] explains, +/// [the Rust compiler assumes][inv] that values are properly initialized. /// As a consequence, calling e.g. `mem::uninitialized::<bool>()` causes immediate /// undefined behavior for returning a `bool` that is not definitely either `true` /// or `false`. Worse, truly uninitialized memory like what gets returned here @@ -521,13 +518,15 @@ pub unsafe fn zeroed<T>() -> T { /// until they are, it is advisable to avoid them.) /// /// [`MaybeUninit<T>`]: union.MaybeUninit.html +/// [uninit]: union.MaybeUninit.html#method.uninit +/// [assume_init]: union.MaybeUninit.html#method.assume_init /// [inv]: union.MaybeUninit.html#initialization-invariant #[inline] #[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")] #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated_in_future)] #[allow(deprecated)] -#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "mem_uninitialized")] +#[rustc_diagnostic_item = "mem_uninitialized"] pub unsafe fn uninitialized<T>() -> T { intrinsics::panic_if_uninhabited::<T>(); intrinsics::uninit() @@ -867,11 +866,5 @@ impl<T> fmt::Debug for Discriminant<T> { /// ``` #[stable(feature = "discriminant_value", since = "1.21.0")] pub fn discriminant<T>(v: &T) -> Discriminant<T> { - #[cfg(bootstrap)] - // SAFETY: going away soon - unsafe { - Discriminant(intrinsics::discriminant_value(v), PhantomData) - } - #[cfg(not(bootstrap))] Discriminant(intrinsics::discriminant_value(v), PhantomData) } diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index ac06f95e244..9e379e63810 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -7,7 +7,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(bootstrap))] use crate::convert::FloatToInt; #[cfg(not(test))] use crate::intrinsics; @@ -423,7 +422,6 @@ impl f32 { /// * Not be `NaN` /// * Not be infinite /// * Be representable in the return type `Int`, after truncating off its fractional part - #[cfg(not(bootstrap))] #[unstable(feature = "float_approx_unchecked_to", issue = "67058")] #[inline] pub unsafe fn approx_unchecked_to<Int>(self) -> Int where Self: FloatToInt<Int> { diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 5446ce3e3b3..540c6a529d7 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -7,7 +7,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(bootstrap))] use crate::convert::FloatToInt; #[cfg(not(test))] use crate::intrinsics; @@ -436,7 +435,6 @@ impl f64 { /// * Not be `NaN` /// * Not be infinite /// * Be representable in the return type `Int`, after truncating off its fractional part - #[cfg(not(bootstrap))] #[unstable(feature = "float_approx_unchecked_to", issue = "67058")] #[inline] pub unsafe fn approx_unchecked_to<Int>(self) -> Int diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index d1f518d52dd..6c864f74b1f 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4,6 +4,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use crate::convert::Infallible; use crate::fmt; use crate::intrinsics; use crate::mem; @@ -60,9 +61,10 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s /// /// The value must not be zero. #[$stability] + #[rustc_const_stable(feature = "nonzero", since = "1.34.0")] #[inline] pub const unsafe fn new_unchecked(n: $Int) -> Self { - $Ty(n) + Self(n) } /// Creates a non-zero if the given value is not zero. @@ -71,7 +73,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s pub fn new(n: $Int) -> Option<Self> { if n != 0 { // SAFETY: we just checked that there's no `0` - Some(unsafe { $Ty(n) }) + Some(unsafe { Self(n) }) } else { None } @@ -80,6 +82,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s /// Returns the value as a primitive type. #[$stability] #[inline] + #[rustc_const_stable(feature = "nonzero", since = "1.34.0")] pub const fn get(self) -> $Int { self.0 } @@ -135,7 +138,7 @@ NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize } /// Provides intentionally-wrapped arithmetic on `T`. /// -/// Operations like `+` on `u32` values is intended to never overflow, +/// Operations like `+` on `u32` values are intended to never overflow, /// and in some debug configurations overflow is detected and results /// in a panic. While most arithmetic falls into this category, some /// code explicitly expects and relies upon modular arithmetic (e.g., @@ -255,6 +258,7 @@ $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline(always)] #[rustc_promotable] + #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")] pub const fn min_value() -> Self { !0 ^ ((!0 as $UnsignedT) >> 1) as Self } @@ -274,6 +278,7 @@ $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline(always)] #[rustc_promotable] + #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] pub const fn max_value() -> Self { !Self::min_value() } @@ -323,6 +328,7 @@ $EndFeature, " ``` "), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } } @@ -338,6 +344,7 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn count_zeros(self) -> u32 { (!self).count_ones() @@ -358,6 +365,7 @@ assert_eq!(n.leading_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn leading_zeros(self) -> u32 { (self as $UnsignedT).leading_zeros() @@ -378,6 +386,7 @@ assert_eq!(n.trailing_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn trailing_zeros(self) -> u32 { (self as $UnsignedT).trailing_zeros() @@ -401,6 +410,7 @@ let m = ", $rot_result, "; assert_eq!(n.rotate_left(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -427,6 +437,7 @@ let m = ", $rot_op, "; assert_eq!(n.rotate_right(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -450,6 +461,7 @@ let m = n.swap_bytes(); assert_eq!(m, ", $swapped, "); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn swap_bytes(self) -> Self { (self as $UnsignedT).swap_bytes() as Self @@ -470,6 +482,7 @@ let m = n.reverse_bits(); assert_eq!(m, ", $reversed, "); ```"), #[stable(feature = "reverse_bits", since = "1.37.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] #[must_use] pub const fn reverse_bits(self) -> Self { @@ -497,6 +510,7 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")] #[inline] pub const fn from_be(x: Self) -> Self { #[cfg(target_endian = "big")] @@ -530,6 +544,7 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")] #[inline] pub const fn from_le(x: Self) -> Self { #[cfg(target_endian = "little")] @@ -563,6 +578,7 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")] #[inline] pub const fn to_be(self) -> Self { // or not to be? #[cfg(target_endian = "big")] @@ -596,6 +612,7 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")] #[inline] pub const fn to_le(self) -> Self { #[cfg(target_endian = "little")] @@ -948,7 +965,7 @@ $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods")] + #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -974,7 +991,7 @@ assert_eq!(", stringify!($SelfT), "::max_value().saturating_sub(-1), ", stringif $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods")] + #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1114,6 +1131,7 @@ assert_eq!(", stringify!($SelfT), "::max_value().wrapping_add(2), ", stringify!( $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1137,6 +1155,7 @@ stringify!($SelfT), "::max_value());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1159,6 +1178,7 @@ assert_eq!(11i8.wrapping_mul(12), -124);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1303,6 +1323,7 @@ assert_eq!(", stringify!($SelfT), "::min_value().wrapping_neg(), ", stringify!($ $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn wrapping_neg(self) -> Self { self.overflowing_neg().0 @@ -1328,6 +1349,7 @@ assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(128), -1);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1359,6 +1381,7 @@ assert_eq!((-128i16).wrapping_shr(64), -128);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1392,6 +1415,7 @@ assert_eq!((-128i8).wrapping_abs() as u8, 128);", $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn wrapping_abs(self) -> Self { // sign is -1 (all ones) for negative numbers, 0 otherwise. @@ -1466,6 +1490,7 @@ assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (", stringify!($Sel "::MIN, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1493,6 +1518,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_sub(1), (", stringify!($Sel "::MAX, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1518,6 +1544,7 @@ assert_eq!(1_000_000_000i32.overflowing_mul(10), (1410065408, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1685,6 +1712,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self ```"), #[inline] #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] pub const fn overflowing_neg(self) -> (Self, bool) { ((!self).wrapping_add(1), self == Self::min_value()) } @@ -1707,6 +1735,7 @@ assert_eq!(0x1i32.overflowing_shl(36), (0x10, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1732,6 +1761,7 @@ assert_eq!(0x10i32.overflowing_shr(36), (0x1, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1760,6 +1790,7 @@ assert_eq!((", stringify!($SelfT), "::min_value()).overflowing_abs(), (", string $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn overflowing_abs(self) -> (Self, bool) { (self.wrapping_abs(), self == Self::min_value()) @@ -1964,6 +1995,7 @@ assert_eq!((-10", stringify!($SelfT), ").abs(), 10);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] #[rustc_inherit_overflow_checks] pub const fn abs(self) -> Self { @@ -2006,7 +2038,7 @@ assert_eq!((-10", stringify!($SelfT), ").signum(), -1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_sign")] + #[rustc_const_unstable(feature = "const_int_sign", issue = "53718")] #[inline] pub const fn signum(self) -> Self { (self > 0) as Self - (self < 0) as Self @@ -2027,6 +2059,7 @@ assert!(!(-10", stringify!($SelfT), ").is_positive());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn is_positive(self) -> bool { self > 0 } } @@ -2045,6 +2078,7 @@ assert!(!10", stringify!($SelfT), ".is_negative());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn is_negative(self) -> bool { self < 0 } } @@ -2062,7 +2096,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes(); assert_eq!(bytes, ", $be_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] { self.to_be().to_ne_bytes() @@ -2082,7 +2116,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes(); assert_eq!(bytes, ", $le_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] { self.to_le().to_ne_bytes() @@ -2117,7 +2151,7 @@ assert_eq!( ); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] { // SAFETY: integers are plain old datatypes so we can always transmute them to @@ -2151,7 +2185,7 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { Self::from_be(Self::from_ne_bytes(bytes)) @@ -2184,7 +2218,7 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { Self::from_le(Self::from_ne_bytes(bytes)) @@ -2227,7 +2261,7 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { // SAFETY: integers are plain old datatypes so we can always transmute to them @@ -2321,6 +2355,7 @@ Basic usage: #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] #[inline(always)] + #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")] pub const fn min_value() -> Self { 0 } } @@ -2338,6 +2373,7 @@ stringify!($MaxV), ");", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] #[inline(always)] + #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] pub const fn max_value() -> Self { !0 } } @@ -2384,6 +2420,7 @@ Basic usage: assert_eq!(n.count_ones(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn count_ones(self) -> u32 { intrinsics::ctpop(self as $ActualT) as u32 @@ -2401,6 +2438,7 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn count_zeros(self) -> u32 { (!self).count_ones() @@ -2420,6 +2458,7 @@ Basic usage: assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn leading_zeros(self) -> u32 { intrinsics::ctlz(self as $ActualT) as u32 @@ -2440,6 +2479,7 @@ Basic usage: assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn trailing_zeros(self) -> u32 { intrinsics::cttz(self) as u32 @@ -2463,6 +2503,7 @@ let m = ", $rot_result, "; assert_eq!(n.rotate_left(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2489,6 +2530,7 @@ let m = ", $rot_op, "; assert_eq!(n.rotate_right(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2512,6 +2554,7 @@ let m = n.swap_bytes(); assert_eq!(m, ", $swapped, "); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn swap_bytes(self) -> Self { intrinsics::bswap(self as $ActualT) as Self @@ -2532,6 +2575,7 @@ let m = n.reverse_bits(); assert_eq!(m, ", $reversed, "); ```"), #[stable(feature = "reverse_bits", since = "1.37.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] #[must_use] pub const fn reverse_bits(self) -> Self { @@ -2559,6 +2603,7 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn from_be(x: Self) -> Self { #[cfg(target_endian = "big")] @@ -2592,6 +2637,7 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn from_le(x: Self) -> Self { #[cfg(target_endian = "little")] @@ -2625,6 +2671,7 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn to_be(self) -> Self { // or not to be? #[cfg(target_endian = "big")] @@ -2658,6 +2705,7 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_math", since = "1.32.0")] #[inline] pub const fn to_le(self) -> Self { #[cfg(target_endian = "little")] @@ -2963,7 +3011,7 @@ assert_eq!(200u8.saturating_add(127), 255);", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[rustc_const_unstable(feature = "const_saturating_int_methods")] + #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] #[inline] pub const fn saturating_add(self, rhs: Self) -> Self { intrinsics::saturating_add(self, rhs) @@ -2985,7 +3033,7 @@ assert_eq!(13", stringify!($SelfT), ".saturating_sub(127), 0);", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[rustc_const_unstable(feature = "const_saturating_int_methods")] + #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] #[inline] pub const fn saturating_sub(self, rhs: Self) -> Self { intrinsics::saturating_sub(self, rhs) @@ -3057,6 +3105,7 @@ assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::ma $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3079,6 +3128,7 @@ assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::ma $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3102,6 +3152,7 @@ $EndFeature, " /// assert_eq!(25u8.wrapping_mul(12), 44); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3231,6 +3282,7 @@ assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0); /// assert_eq!((-128i8).wrapping_neg(), -128); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[inline] pub const fn wrapping_neg(self) -> Self { self.overflowing_neg().0 @@ -3257,6 +3309,7 @@ Basic usage: assert_eq!(1", stringify!($SelfT), ".wrapping_shl(128), 1);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3290,6 +3343,7 @@ Basic usage: assert_eq!(128", stringify!($SelfT), ".wrapping_shr(128), 128);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3359,6 +3413,7 @@ assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false)); assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3387,6 +3442,7 @@ assert_eq!(0", stringify!($SelfT), ".overflowing_sub(1), (", stringify!($SelfT), $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3414,6 +3470,7 @@ $EndFeature, " /// assert_eq!(1_000_000_000u32.overflowing_mul(10), (1410065408, true)); /// ``` #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3559,6 +3616,7 @@ assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2i32 as ", stringify!( ```"), #[inline] #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] pub const fn overflowing_neg(self) -> (Self, bool) { ((!self).wrapping_add(1), self != 0) } @@ -3582,6 +3640,7 @@ Basic usage assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(132), (0x10, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3608,6 +3667,7 @@ Basic usage assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(132), (0x1, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3773,6 +3833,7 @@ Basic usage: assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_is_power_of_two", since = "1.32.0")] #[inline] pub const fn is_power_of_two(self) -> bool { self.count_ones() == 1 @@ -3884,7 +3945,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes(); assert_eq!(bytes, ", $be_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] { self.to_be().to_ne_bytes() @@ -3904,7 +3965,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes(); assert_eq!(bytes, ", $le_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] { self.to_le().to_ne_bytes() @@ -3939,7 +4000,7 @@ assert_eq!( ); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] { // SAFETY: integers are plain old datatypes so we can always transmute them to @@ -3973,7 +4034,7 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { Self::from_be(Self::from_ne_bytes(bytes)) @@ -4006,7 +4067,7 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { Self::from_le(Self::from_ne_bytes(bytes)) @@ -4049,7 +4110,7 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")] #[inline] pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { // SAFETY: integers are plain old datatypes so we can always transmute to them @@ -4724,8 +4785,18 @@ impl fmt::Display for TryFromIntError { } #[stable(feature = "try_from", since = "1.34.0")] +impl From<Infallible> for TryFromIntError { + fn from(x: Infallible) -> TryFromIntError { + match x {} + } +} + +#[unstable(feature = "never_type", issue = "35121")] impl From<!> for TryFromIntError { fn from(never: !) -> TryFromIntError { + // Match rather than coerce to make sure that code like + // `From<Infallible> for TryFromIntError` above will keep working + // when `Infallible` becomes an alias to `!`. match never {} } } diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 0ddfbd02aa5..82fa6acfbd6 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -530,6 +530,7 @@ assert_eq!(n.trailing_zeros(), 3); /// assert_eq!(m, Wrapping(-22016)); /// ``` #[stable(feature = "reverse_bits", since = "1.37.0")] + #[rustc_const_stable(feature = "const_reverse_bits", since = "1.37.0")] #[inline] #[must_use] pub const fn reverse_bits(self) -> Self { diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index a2250337a4d..be6d8edb99f 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -398,6 +398,7 @@ impl<Idx> RangeInclusive<Idx> { #[stable(feature = "inclusive_range_methods", since = "1.27.0")] #[inline] #[rustc_promotable] + #[rustc_const_stable(feature = "const_range_new", since = "1.32.0")] pub const fn new(start: Idx, end: Idx) -> Self { Self { start, end, is_empty: None } } @@ -421,6 +422,7 @@ impl<Idx> RangeInclusive<Idx> { /// assert_eq!((3..=5).start(), &3); /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] + #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")] #[inline] pub const fn start(&self) -> &Idx { &self.start @@ -445,6 +447,7 @@ impl<Idx> RangeInclusive<Idx> { /// assert_eq!((3..=5).end(), &5); /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] + #[rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0")] #[inline] pub const fn end(&self) -> &Idx { &self.end diff --git a/src/libcore/ops/try.rs b/src/libcore/ops/try.rs index 22ba97b91df..996a01d413c 100644 --- a/src/libcore/ops/try.rs +++ b/src/libcore/ops/try.rs @@ -5,26 +5,23 @@ /// extracting those success or failure values from an existing instance and /// creating a new instance from a success or failure value. #[unstable(feature = "try_trait", issue = "42327")] -#[cfg_attr( - not(bootstrap), - rustc_on_unimplemented( - on( - all( - any(from_method = "from_error", from_method = "from_ok"), - from_desugaring = "QuestionMark" - ), - message = "the `?` operator can only be used in {ItemContext} \ - that returns `Result` or `Option` \ - (or another type that implements `{Try}`)", - label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`", - enclosing_scope = "this function should return `Result` or `Option` to accept `?`" +#[rustc_on_unimplemented( + on( + all( + any(from_method = "from_error", from_method = "from_ok"), + from_desugaring = "QuestionMark" ), - on( - all(from_method = "into_result", from_desugaring = "QuestionMark"), - message = "the `?` operator can only be applied to values \ - that implement `{Try}`", - label = "the `?` operator cannot be applied to type `{Self}`" - ) + message = "the `?` operator can only be used in {ItemContext} \ + that returns `Result` or `Option` \ + (or another type that implements `{Try}`)", + label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`", + enclosing_scope = "this function should return `Result` or `Option` to accept `?`" + ), + on( + all(from_method = "into_result", from_desugaring = "QuestionMark"), + message = "the `?` operator can only be applied to values \ + that implement `{Try}`", + label = "the `?` operator cannot be applied to type `{Self}`" ) )] #[doc(alias = "?")] diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index e924ee20369..c9a1c4b0049 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -1,8 +1,6 @@ //! Panic support in the standard library. -#![unstable(feature = "core_panic_info", - reason = "newly available in libcore", - issue = "44489")] +#![stable(feature = "core_panic_info", since = "1.41.0")] use crate::any::Any; use crate::fmt; @@ -39,10 +37,10 @@ pub struct PanicInfo<'a> { } impl<'a> PanicInfo<'a> { - #![unstable(feature = "panic_internals", - reason = "internal details of the implementation of the `panic!` \ - and related macros", - issue = "0")] + #[unstable(feature = "panic_internals", + reason = "internal details of the implementation of the `panic!` \ + and related macros", + issue = "0")] #[doc(hidden)] #[inline] pub fn internal_constructor( @@ -57,6 +55,10 @@ impl<'a> PanicInfo<'a> { } } + #[unstable(feature = "panic_internals", + reason = "internal details of the implementation of the `panic!` \ + and related macros", + issue = "0")] #[doc(hidden)] #[inline] pub fn set_payload(&mut self, info: &'a (dyn Any + Send)) { @@ -90,7 +92,7 @@ impl<'a> PanicInfo<'a> { /// returns that message ready to be used for example with [`fmt::write`] /// /// [`fmt::write`]: ../fmt/fn.write.html - #[unstable(feature = "panic_info_message", issue = "44489")] + #[unstable(feature = "panic_info_message", issue = "66745")] pub fn message(&self) -> Option<&fmt::Arguments<'_>> { self.message } @@ -220,7 +222,6 @@ impl<'a> Location<'a> { /// assert_ne!(this_location.line(), another_location.line()); /// assert_ne!(this_location.column(), another_location.column()); /// ``` - #[cfg(not(bootstrap))] #[unstable(feature = "track_caller", reason = "uses #[track_caller] which is not yet stable", issue = "47809")] diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 24ffa348329..776165e7bd7 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -198,6 +198,7 @@ unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[rustc_const_stable(feature = "const_ptr_null", since = "1.32.0")] pub const fn null<T>() -> *const T { 0 as *const T } @@ -215,6 +216,7 @@ pub const fn null<T>() -> *const T { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[rustc_const_stable(feature = "const_ptr_null", since = "1.32.0")] pub const fn null_mut<T>() -> *mut T { 0 as *mut T } @@ -1060,6 +1062,7 @@ impl<T: ?Sized> *const T { /// Casts to a pointer of another type. #[stable(feature = "ptr_cast", since = "1.38.0")] + #[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")] #[inline] pub const fn cast<U>(self) -> *const U { self as _ @@ -1307,7 +1310,7 @@ impl<T: ?Sized> *const T { /// } /// ``` #[unstable(feature = "ptr_offset_from", issue = "41079")] - #[rustc_const_unstable(feature = "const_ptr_offset_from")] + #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")] #[inline] pub const unsafe fn offset_from(self, origin: *const T) -> isize where @@ -1763,6 +1766,7 @@ impl<T: ?Sized> *mut T { /// Casts to a pointer of another type. #[stable(feature = "ptr_cast", since = "1.38.0")] + #[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")] #[inline] pub const fn cast<U>(self) -> *mut U { self as _ @@ -2049,7 +2053,7 @@ impl<T: ?Sized> *mut T { /// } /// ``` #[unstable(feature = "ptr_offset_from", issue = "41079")] - #[rustc_const_unstable(feature = "const_ptr_offset_from")] + #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")] #[inline] pub const unsafe fn offset_from(self, origin: *const T) -> isize where diff --git a/src/libcore/ptr/non_null.rs b/src/libcore/ptr/non_null.rs index a121389bef3..6946fd2413e 100644 --- a/src/libcore/ptr/non_null.rs +++ b/src/libcore/ptr/non_null.rs @@ -66,6 +66,7 @@ impl<T: Sized> NonNull<T> { /// sentinel value. Types that lazily allocate must track initialization by /// some other means. #[stable(feature = "nonnull", since = "1.25.0")] + #[rustc_const_stable(feature = "const_nonnull_dangling", since = "1.32.0")] #[inline] pub const fn dangling() -> Self { unsafe { @@ -82,6 +83,7 @@ impl<T: ?Sized> NonNull<T> { /// /// `ptr` must be non-null. #[stable(feature = "nonnull", since = "1.25.0")] + #[rustc_const_stable(feature = "const_nonnull_new_unchecked", since = "1.32.0")] #[inline] pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { NonNull { pointer: ptr as _ } @@ -96,6 +98,7 @@ impl<T: ?Sized> NonNull<T> { /// Acquires the underlying `*mut` pointer. #[stable(feature = "nonnull", since = "1.25.0")] + #[rustc_const_stable(feature = "const_nonnull_as_ptr", since = "1.32.0")] #[inline] pub const fn as_ptr(self) -> *mut T { self.pointer as *mut T @@ -125,6 +128,7 @@ impl<T: ?Sized> NonNull<T> { /// Casts to a pointer of another type. #[stable(feature = "nonnull_cast", since = "1.27.0")] + #[rustc_const_stable(feature = "const_nonnull_cast", since = "1.32.0")] #[inline] pub const fn cast<U>(self) -> NonNull<U> { unsafe { NonNull::new_unchecked(self.as_ptr() as *mut U) } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 1a0845f3a6d..fb4dc62d8c1 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -520,7 +520,6 @@ impl<T, E> Result<T, E> { /// # Examples /// /// ``` - /// #![feature(result_map_or)] /// let x: Result<_, &str> = Ok("foo"); /// assert_eq!(x.map_or(42, |v| v.len()), 3); /// @@ -528,7 +527,7 @@ impl<T, E> Result<T, E> { /// assert_eq!(x.map_or(42, |v| v.len()), 42); /// ``` #[inline] - #[unstable(feature = "result_map_or", issue = "66293")] + #[stable(feature = "result_map_or", since = "1.41.0")] pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U { match self { Ok(t) => f(t), diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index c8fe9f98613..05baa1899b3 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -62,6 +62,7 @@ impl<T> [T] { /// assert_eq!(a.len(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_slice_len", since = "1.32.0")] #[inline] // SAFETY: const sound because we transmute out the length field as a usize (which it must be) #[allow(unused_attributes)] @@ -81,6 +82,7 @@ impl<T> [T] { /// assert!(!a.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_slice_is_empty", since = "1.32.0")] #[inline] pub const fn is_empty(&self) -> bool { self.len() == 0 @@ -376,6 +378,7 @@ impl<T> [T] { /// /// [`as_mut_ptr`]: #method.as_mut_ptr #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")] #[inline] pub const fn as_ptr(&self) -> *const T { self as *const [T] as *const T diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index b2a420f3c43..3da992dca30 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -8,7 +8,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use self::pattern::Pattern; -use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher}; +use self::pattern::{Searcher, SearchStep, ReverseSearcher, DoubleEndedSearcher}; use crate::char; use crate::fmt::{self, Write}; @@ -2090,6 +2090,7 @@ impl str { /// assert_eq!("ƒoo".chars().count(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_str_len", since = "1.32.0")] #[inline] pub const fn len(&self) -> usize { self.as_bytes().len() @@ -2110,6 +2111,7 @@ impl str { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_str_is_empty", since = "1.32.0")] pub const fn is_empty(&self) -> bool { self.len() == 0 } @@ -2166,6 +2168,7 @@ impl str { /// assert_eq!(b"bors", bytes); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "str_as_bytes", since = "1.32.0")] #[inline(always)] // SAFETY: const sound because we transmute two types with the same layout #[allow(unused_attributes)] @@ -2239,6 +2242,7 @@ impl str { /// let ptr = s.as_ptr(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "rustc_str_as_ptr", since = "1.32.0")] #[inline] pub const fn as_ptr(&self) -> *const u8 { self as *const str as *const u8 @@ -3791,6 +3795,77 @@ impl str { } } + /// Returns a string slice with the prefix removed. + /// + /// If the string starts with the pattern `prefix`, `Some` is returned with the substring where + /// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly + /// once. + /// + /// If the string does not start with `prefix`, `None` is returned. + /// + /// # Examples + /// + /// ``` + /// #![feature(str_strip)] + /// + /// assert_eq!("foobar".strip_prefix("foo"), Some("bar")); + /// assert_eq!("foobar".strip_prefix("bar"), None); + /// assert_eq!("foofoo".strip_prefix("foo"), Some("foo")); + /// ``` + #[must_use = "this returns the remaining substring as a new slice, \ + without modifying the original"] + #[unstable(feature = "str_strip", reason = "newly added", issue = "67302")] + pub fn strip_prefix<'a, P: Pattern<'a>>(&'a self, prefix: P) -> Option<&'a str> { + let mut matcher = prefix.into_searcher(self); + if let SearchStep::Match(start, len) = matcher.next() { + debug_assert_eq!(start, 0, "The first search step from Searcher \ + must include the first character"); + unsafe { + // Searcher is known to return valid indices. + Some(self.get_unchecked(len..)) + } + } else { + None + } + } + + /// Returns a string slice with the suffix removed. + /// + /// If the string ends with the pattern `suffix`, `Some` is returned with the substring where + /// the suffix is removed. Unlike `trim_end_matches`, this method removes the suffix exactly + /// once. + /// + /// If the string does not end with `suffix`, `None` is returned. + /// + /// # Examples + /// + /// ``` + /// #![feature(str_strip)] + /// assert_eq!("barfoo".strip_suffix("foo"), Some("bar")); + /// assert_eq!("barfoo".strip_suffix("bar"), None); + /// assert_eq!("foofoo".strip_suffix("foo"), Some("foo")); + /// ``` + #[must_use = "this returns the remaining substring as a new slice, \ + without modifying the original"] + #[unstable(feature = "str_strip", reason = "newly added", issue = "67302")] + pub fn strip_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str> + where + P: Pattern<'a>, + <P as Pattern<'a>>::Searcher: ReverseSearcher<'a>, + { + let mut matcher = suffix.into_searcher(self); + if let SearchStep::Match(start, end) = matcher.next_back() { + debug_assert_eq!(end, self.len(), "The first search step from ReverseSearcher \ + must include the last character"); + unsafe { + // Searcher is known to return valid indices. + Some(self.get_unchecked(..start)) + } + } else { + None + } + } + /// Returns a string slice with all suffixes that match a pattern /// repeatedly removed. /// diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 1037da14b5f..b7ebd5f88b5 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -445,21 +445,13 @@ impl<'a> Pattern<'a> for char { #[inline] fn is_prefix_of(self, haystack: &'a str) -> bool { - if let Some(ch) = haystack.chars().next() { - self == ch - } else { - false - } + self.encode_utf8(&mut [0u8; 4]).is_prefix_of(haystack) } #[inline] fn is_suffix_of(self, haystack: &'a str) -> bool where Self::Searcher: ReverseSearcher<'a> { - if let Some(ch) = haystack.chars().next_back() { - self == ch - } else { - false - } + self.encode_utf8(&mut [0u8; 4]).is_suffix_of(haystack) } } @@ -710,16 +702,13 @@ impl<'a, 'b> Pattern<'a> for &'b str { /// Checks whether the pattern matches at the front of the haystack #[inline] fn is_prefix_of(self, haystack: &'a str) -> bool { - haystack.is_char_boundary(self.len()) && - self == &haystack[..self.len()] + haystack.as_bytes().starts_with(self.as_bytes()) } /// Checks whether the pattern matches at the back of the haystack #[inline] fn is_suffix_of(self, haystack: &'a str) -> bool { - self.len() <= haystack.len() && - haystack.is_char_boundary(haystack.len() - self.len()) && - self == &haystack[haystack.len() - self.len()..] + haystack.as_bytes().ends_with(self.as_bytes()) } } diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 6e1aac00c7b..1f09895597a 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -331,6 +331,7 @@ impl AtomicBool { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_atomic_new", since = "1.32.0")] pub const fn new(v: bool) -> AtomicBool { AtomicBool { v: UnsafeCell::new(v as u8) } } @@ -855,6 +856,7 @@ impl<T> AtomicPtr<T> { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_atomic_new", since = "1.32.0")] pub const fn new(p: *mut T) -> AtomicPtr<T> { AtomicPtr { p: UnsafeCell::new(p) } } @@ -1183,6 +1185,7 @@ macro_rules! atomic_int { $stable_access:meta, $stable_from:meta, $stable_nand:meta, + $const_stable:meta, $stable_init_const:meta, $s_int_type:expr, $int_ref:expr, $extra_feature:expr, @@ -1258,8 +1261,9 @@ let atomic_forty_two = ", stringify!($atomic_type), "::new(42); ```"), #[inline] #[$stable] + #[$const_stable] pub const fn new(v: $int_type) -> Self { - $atomic_type {v: UnsafeCell::new(v)} + Self {v: UnsafeCell::new(v)} } } @@ -1978,6 +1982,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "i8", "../../../std/primitive.i8.html", "", @@ -1995,6 +2000,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "u8", "../../../std/primitive.u8.html", "", @@ -2012,6 +2018,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "i16", "../../../std/primitive.i16.html", "", @@ -2029,6 +2036,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "u16", "../../../std/primitive.u16.html", "", @@ -2046,6 +2054,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "i32", "../../../std/primitive.i32.html", "", @@ -2063,6 +2072,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "u32", "../../../std/primitive.u32.html", "", @@ -2080,6 +2090,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "i64", "../../../std/primitive.i64.html", "", @@ -2097,6 +2108,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), stable(feature = "integer_atomics_stable", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "u64", "../../../std/primitive.u64.html", "", @@ -2114,6 +2126,7 @@ atomic_int! { unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "i128", "../../../std/primitive.i128.html", "#![feature(integer_atomics)]\n\n", @@ -2131,6 +2144,7 @@ atomic_int! { unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), "u128", "../../../std/primitive.u128.html", "#![feature(integer_atomics)]\n\n", @@ -2163,6 +2177,7 @@ atomic_int!{ stable(feature = "atomic_access", since = "1.15.0"), stable(feature = "atomic_from", since = "1.23.0"), stable(feature = "atomic_nand", since = "1.27.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), stable(feature = "rust1", since = "1.0.0"), "isize", "../../../std/primitive.isize.html", "", @@ -2180,6 +2195,7 @@ atomic_int!{ stable(feature = "atomic_access", since = "1.15.0"), stable(feature = "atomic_from", since = "1.23.0"), stable(feature = "atomic_nand", since = "1.27.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), stable(feature = "rust1", since = "1.0.0"), "usize", "../../../std/primitive.usize.html", "", diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index 0759ff93ea8..b070b665b4d 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -39,6 +39,7 @@ impl RawWaker { /// function in the `vtable` of the underlying `RawWaker` will be called. #[rustc_promotable] #[stable(feature = "futures_api", since = "1.36.0")] + #[rustc_const_stable(feature = "futures_api", since = "1.36.0")] pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker { RawWaker { data, vtable } } @@ -151,6 +152,7 @@ impl RawWakerVTable { // FIXME: remove whenever we have a stable way to accept fn pointers from const fn // (see https://github.com/rust-rfcs/const-eval/issues/19#issuecomment-472799062) #[rustc_allow_const_fn_ptr] + #[rustc_const_stable(feature = "futures_api", since = "1.36.0")] pub const fn new( clone: unsafe fn(*const ()) -> RawWaker, wake: unsafe fn(*const ()), diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 70ec1e42fd7..c1d405239f9 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -130,6 +130,7 @@ impl Duration { /// ``` #[stable(feature = "duration", since = "1.3.0")] #[inline] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub fn new(secs: u64, nanos: u32) -> Duration { let secs = secs.checked_add((nanos / NANOS_PER_SEC) as u64).expect("overflow in Duration::new"); @@ -152,6 +153,7 @@ impl Duration { #[stable(feature = "duration", since = "1.3.0")] #[inline] #[rustc_promotable] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_secs(secs: u64) -> Duration { Duration { secs, nanos: 0 } } @@ -171,6 +173,7 @@ impl Duration { #[stable(feature = "duration", since = "1.3.0")] #[inline] #[rustc_promotable] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_millis(millis: u64) -> Duration { Duration { secs: millis / MILLIS_PER_SEC, @@ -193,6 +196,7 @@ impl Duration { #[stable(feature = "duration_from_micros", since = "1.27.0")] #[inline] #[rustc_promotable] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_micros(micros: u64) -> Duration { Duration { secs: micros / MICROS_PER_SEC, @@ -215,6 +219,7 @@ impl Duration { #[stable(feature = "duration_extras", since = "1.27.0")] #[inline] #[rustc_promotable] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_nanos(nanos: u64) -> Duration { Duration { secs: nanos / (NANOS_PER_SEC as u64), @@ -251,6 +256,7 @@ impl Duration { /// /// [`subsec_nanos`]: #method.subsec_nanos #[stable(feature = "duration", since = "1.3.0")] + #[rustc_const_stable(feature = "duration", since = "1.32.0")] #[inline] pub const fn as_secs(&self) -> u64 { self.secs @@ -272,6 +278,7 @@ impl Duration { /// assert_eq!(duration.subsec_millis(), 432); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] + #[rustc_const_stable(feature = "duration_extras", since = "1.32.0")] #[inline] pub const fn subsec_millis(&self) -> u32 { self.nanos / NANOS_PER_MILLI @@ -293,6 +300,7 @@ impl Duration { /// assert_eq!(duration.subsec_micros(), 234_567); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] + #[rustc_const_stable(feature = "duration_extras", since = "1.32.0")] #[inline] pub const fn subsec_micros(&self) -> u32 { self.nanos / NANOS_PER_MICRO @@ -314,6 +322,7 @@ impl Duration { /// assert_eq!(duration.subsec_nanos(), 10_000_000); /// ``` #[stable(feature = "duration", since = "1.3.0")] + #[rustc_const_stable(feature = "duration", since = "1.32.0")] #[inline] pub const fn subsec_nanos(&self) -> u32 { self.nanos @@ -330,6 +339,7 @@ impl Duration { /// assert_eq!(duration.as_millis(), 5730); /// ``` #[stable(feature = "duration_as_u128", since = "1.33.0")] + #[rustc_const_stable(feature = "duration_as_u128", since = "1.33.0")] #[inline] pub const fn as_millis(&self) -> u128 { self.secs as u128 * MILLIS_PER_SEC as u128 + (self.nanos / NANOS_PER_MILLI) as u128 @@ -346,6 +356,7 @@ impl Duration { /// assert_eq!(duration.as_micros(), 5730023); /// ``` #[stable(feature = "duration_as_u128", since = "1.33.0")] + #[rustc_const_stable(feature = "duration_as_u128", since = "1.33.0")] #[inline] pub const fn as_micros(&self) -> u128 { self.secs as u128 * MICROS_PER_SEC as u128 + (self.nanos / NANOS_PER_MICRO) as u128 @@ -362,6 +373,7 @@ impl Duration { /// assert_eq!(duration.as_nanos(), 5730023852); /// ``` #[stable(feature = "duration_as_u128", since = "1.33.0")] + #[rustc_const_stable(feature = "duration_as_u128", since = "1.33.0")] #[inline] pub const fn as_nanos(&self) -> u128 { self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 |
