From 5e17e3988165d3245e38af0b1c40cde47699f6a7 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sun, 8 Dec 2019 01:43:10 +0100 Subject: [PATCH] Require stable/unstable annotations for the constness of all stable functions with a `const` modifier --- src/liballoc/collections/linked_list.rs | 4 + src/liballoc/string.rs | 4 + src/liballoc/vec.rs | 4 + src/libcore/alloc.rs | 1 + src/libcore/any.rs | 9 +- src/libcore/cell.rs | 11 + src/libcore/char/methods.rs | 4 + src/libcore/convert/mod.rs | 1 + src/libcore/intrinsics.rs | 6 +- src/libcore/iter/sources.rs | 1 + src/libcore/mem/manually_drop.rs | 8 + src/libcore/mem/maybe_uninit.rs | 8 + src/libcore/mem/mod.rs | 3 + src/libcore/num/mod.rs | 342 +++++++++++++++++- src/libcore/num/wrapping.rs | 4 + src/libcore/ops/range.rs | 9 + src/libcore/ptr/mod.rs | 16 +- src/libcore/ptr/non_null.rs | 16 + src/libcore/slice/mod.rs | 9 + src/libcore/str/mod.rs | 7 + src/libcore/sync/atomic.rs | 81 +++++ src/libcore/task/wake.rs | 2 + src/libcore/time.rs | 12 + src/librustc/middle/stability.rs | 22 +- src/librustc/query/mod.rs | 1 + src/librustc/ty/constness.rs | 45 ++- src/librustc/ty/context.rs | 17 + src/librustc_feature/builtin_attrs.rs | 2 + src/librustc_metadata/rmeta/decoder.rs | 4 + .../rmeta/decoder/cstore_impl.rs | 3 + src/librustc_metadata/rmeta/encoder.rs | 11 + src/librustc_metadata/rmeta/mod.rs | 1 + src/libstd/ffi/c_str.rs | 4 +- src/libstd/net/ip.rs | 4 + src/libstd/sync/once.rs | 1 + src/libsyntax/attr/builtin.rs | 125 +++---- src/libsyntax_expand/base.rs | 6 +- src/libsyntax_pos/symbol.rs | 1 + .../auxiliary/promotable_const_fn_lib.rs | 2 + .../consts/const-eval/auxiliary/stability.rs | 2 +- .../dont_promote_unstable_const_fn.rs | 2 +- .../consts/min_const_fn/allow_const_fn_ptr.rs | 2 + .../min_const_fn/allow_const_fn_ptr.stderr | 2 +- .../allow_const_fn_ptr_run_pass.rs | 1 + .../min_const_fn_libstd_stability.rs | 6 +- .../min_const_fn_libstd_stability.stderr | 8 +- .../min_const_unsafe_fn_libstd_stability.rs | 6 +- ...in_const_unsafe_fn_libstd_stability.stderr | 8 +- .../min_const_unsafe_fn_libstd_stability2.rs | 5 +- ...n_const_unsafe_fn_libstd_stability2.stderr | 6 +- .../ui/consts/unstable-const-fn-in-libcore.rs | 2 +- .../feature-gate/allow-features-empty.stderr | 12 +- .../ui/feature-gate/allow-features.stderr | 10 +- .../feature-gate-rustc_const_unstable.stderr | 8 +- src/test/ui/invalid_const_promotion.rs | 1 + .../stability-attribute-sanity.rs | 5 +- .../stability-attribute-sanity.stderr | 10 +- src/tools/tidy/src/error_codes_check.rs | 2 - 58 files changed, 754 insertions(+), 155 deletions(-) diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 6ee22834a46..4a74a479e71 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -275,6 +275,10 @@ impl LinkedList { /// let list: LinkedList = LinkedList::new(); /// ``` #[inline] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_linked_list_new", since = "1.32.0"), + )] #[stable(feature = "rust1", since = "1.0.0")] pub const fn new() -> Self { LinkedList { diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index f7dff4c21f7..bf9bbba4753 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -367,6 +367,10 @@ impl String { /// let s = String::new(); /// ``` #[inline] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_string_new", since = "1.32.0"), + )] #[stable(feature = "rust1", since = "1.0.0")] pub const fn new() -> String { String { vec: Vec::new() } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 6e165ccb919..52b45b0b8fe 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -315,6 +315,10 @@ impl Vec { /// let mut vec: Vec = Vec::new(); /// ``` #[inline] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_vec_new", since = "1.32.0"), + )] #[stable(feature = "rust1", since = "1.0.0")] pub const fn new() -> Vec { Vec { diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 5c24e3d8f5d..71517ffb006 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -100,6 +100,7 @@ pub fn from_size_align(size: usize, align: usize) -> Result { /// 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")] + #[cfg_attr(not(bootstrap), 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..b0e3021e0bf 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -423,7 +423,8 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature="const_type_id"))] + #[cfg_attr(not(bootstrap), rustc_const_unstable(feature="const_type_id", issue = "41875"))] pub const fn of() -> TypeId { TypeId { #[cfg(bootstrap)] @@ -461,7 +462,8 @@ pub const fn of() -> TypeId { /// ); /// ``` #[stable(feature = "type_name", since = "1.38.0")] -#[rustc_const_unstable(feature = "const_type_name")] +#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_type_name"))] +#[cfg_attr(not(bootstrap), rustc_const_unstable(feature = "const_type_name", issue = "63084"))] pub const fn type_name() -> &'static str { intrinsics::type_name::() } @@ -499,7 +501,8 @@ pub const fn type_name() -> &'static str { /// println!("{}", type_name_of_val(&y)); /// ``` #[unstable(feature = "type_name_of_val", issue = "66359")] -#[rustc_const_unstable(feature = "const_type_name")] +#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_type_name"))] +#[cfg_attr(not(bootstrap), rustc_const_unstable(feature = "const_type_name", issue = "63084"))] pub const fn type_name_of_val(val: &T) -> &'static str { let _ = val; type_name::() diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 03f32e72618..e4b4cd31c63 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -324,6 +324,7 @@ impl Cell { /// let c = Cell::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_cell_new", since = "1.32.0"))] #[inline] pub const fn new(value: T) -> Cell { Cell { @@ -469,6 +470,7 @@ impl Cell { /// ``` #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] + #[cfg_attr(not(bootstrap), 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 RefCell { /// let c = RefCell::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_refcell_new", since = "1.32.0"))] #[inline] pub const fn new(value: T) -> RefCell { RefCell { @@ -1501,6 +1504,10 @@ impl UnsafeCell { /// let uc = UnsafeCell::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0"), + )] #[inline] pub const fn new(value: T) -> UnsafeCell { UnsafeCell { value } @@ -1543,6 +1550,10 @@ impl UnsafeCell { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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` 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..5cfb9583a86 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -911,6 +911,10 @@ pub fn to_uppercase(self) -> ToUppercase { /// assert!(!non_ascii.is_ascii()); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[cfg_attr( + not(bootstrap), + 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/convert/mod.rs b/src/libcore/convert/mod.rs index 5414d9ac234..27d78b55a75 100644 --- a/src/libcore/convert/mod.rs +++ b/src/libcore/convert/mod.rs @@ -99,6 +99,7 @@ /// assert_eq!(vec![1, 3], filtered); /// ``` #[stable(feature = "convert_id", since = "1.33.0")] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_identity", since = "1.33.0"))] #[inline] pub const fn identity(x: T) -> T { x diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 18aae59573d..1f72b7ab090 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -939,7 +939,11 @@ /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_transmute")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_transmute"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_transmute", issue = "53605"), + )] pub fn transmute(e: T) -> U; /// Returns `true` if the actual type given as `T` requires drop diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index ffac7d4e995..127b778e62e 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -281,6 +281,7 @@ fn default() -> Empty { /// assert_eq!(None, nope.next()); /// ``` #[stable(feature = "iter_empty", since = "1.2.0")] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_iter_empty", since = "1.32.0"))] pub const fn empty() -> Empty { Empty(marker::PhantomData) } diff --git a/src/libcore/mem/manually_drop.rs b/src/libcore/mem/manually_drop.rs index 34fc0618ea2..6463668a03e 100644 --- a/src/libcore/mem/manually_drop.rs +++ b/src/libcore/mem/manually_drop.rs @@ -63,6 +63,10 @@ impl ManuallyDrop { /// ManuallyDrop::new(Box::new(())); /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_manually_drop", since = "1.36.0"), + )] #[inline(always)] pub const fn new(value: T) -> ManuallyDrop { ManuallyDrop { value } @@ -80,6 +84,10 @@ pub const fn new(value: T) -> ManuallyDrop { /// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`. /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_manually_drop", since = "1.36.0"), + )] #[inline(always)] pub const fn into_inner(slot: ManuallyDrop) -> T { slot.value diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index 6661df2ae0d..670a194e2d6 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -250,6 +250,10 @@ impl MaybeUninit { /// /// [`assume_init`]: #method.assume_init #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0"), + )] #[inline(always)] pub const fn new(val: T) -> MaybeUninit { MaybeUninit { value: ManuallyDrop::new(val) } @@ -264,6 +268,10 @@ pub const fn new(val: T) -> MaybeUninit { /// /// [type]: union.MaybeUninit.html #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0"), + )] #[inline(always)] #[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_uninit")] pub const fn uninit() -> MaybeUninit { diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index bba441464ff..c50a8ad6000 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -271,6 +271,7 @@ pub fn forget_unsized(t: T) { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_size_of", since = "1.32.0"))] pub const fn size_of() -> usize { intrinsics::size_of::() } @@ -371,6 +372,7 @@ pub fn min_align_of_val(val: &T) -> usize { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_align_of", since = "1.32.0"))] pub const fn align_of() -> usize { intrinsics::min_align_of::() } @@ -453,6 +455,7 @@ pub fn align_of_val(val: &T) -> usize { /// ``` #[inline] #[stable(feature = "needs_drop", since = "1.21.0")] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_needs_drop", since = "1.36.0"))] pub const fn needs_drop() -> bool { intrinsics::needs_drop::() } diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index d1f518d52dd..5a97aa4acfa 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -60,6 +60,10 @@ impl $Ty { /// /// The value must not be zero. #[$stability] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "nonzero", since = "1.34.0"), + )] #[inline] pub const unsafe fn new_unchecked(n: $Int) -> Self { $Ty(n) @@ -80,6 +84,10 @@ pub fn new(n: $Int) -> Option { /// Returns the value as a primitive type. #[$stability] #[inline] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "nonzero", since = "1.34.0"), + )] pub const fn get(self) -> $Int { self.0 } @@ -255,6 +263,10 @@ macro_rules! int_impl { #[stable(feature = "rust1", since = "1.0.0")] #[inline(always)] #[rustc_promotable] + #[cfg_attr( + not(bootstrap), + 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 +286,10 @@ pub const fn min_value() -> Self { #[stable(feature = "rust1", since = "1.0.0")] #[inline(always)] #[rustc_promotable] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_max_value", since = "1.32.0"), + )] pub const fn max_value() -> Self { !Self::min_value() } @@ -323,6 +339,10 @@ pub fn from_str_radix(src: &str, radix: u32) -> Result { ``` "), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +358,10 @@ pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_int_methods", since = "1.32.0"), + )] #[inline] pub const fn count_zeros(self) -> u32 { (!self).count_ones() @@ -358,6 +382,10 @@ pub const fn count_zeros(self) -> u32 { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +406,10 @@ pub const fn leading_zeros(self) -> u32 { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +433,10 @@ pub const fn trailing_zeros(self) -> u32 { assert_eq!(n.rotate_left(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +463,10 @@ pub const fn rotate_left(self, n: u32) -> Self { assert_eq!(n.rotate_right(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +490,10 @@ pub const fn rotate_right(self, n: u32) -> Self { assert_eq!(m, ", $swapped, "); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +514,10 @@ pub const fn swap_bytes(self) -> Self { assert_eq!(m, ", $reversed, "); ```"), #[stable(feature = "reverse_bits", since = "1.37.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_int_methods", since = "1.32.0"), + )] #[inline] #[must_use] pub const fn reverse_bits(self) -> Self { @@ -497,6 +545,10 @@ pub const fn reverse_bits(self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +582,10 @@ pub const fn from_be(x: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +619,10 @@ pub const fn from_le(x: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +656,10 @@ pub const fn to_be(self) -> Self { // or not to be? $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +1012,11 @@ pub fn checked_pow(self, mut exp: u32) -> Option { ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_saturating_int_methods"))] + #[cfg_attr( + not(bootstrap), + 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 +1042,11 @@ pub const fn saturating_add(self, rhs: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_saturating_int_methods"))] + #[cfg_attr( + not(bootstrap), + 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 +1186,10 @@ pub fn saturating_pow(self, exp: u32) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +1213,10 @@ pub const fn wrapping_add(self, rhs: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +1239,10 @@ pub const fn wrapping_sub(self, rhs: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +1387,10 @@ pub fn wrapping_rem_euclid(self, rhs: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[cfg_attr( + not(bootstrap), + 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 +1416,10 @@ pub const fn wrapping_neg(self) -> Self { $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[cfg_attr( + not(bootstrap), + 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 +1451,10 @@ pub const fn wrapping_shl(self, rhs: u32) -> Self { $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[cfg_attr( + not(bootstrap), + 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 +1488,10 @@ pub const fn wrapping_shr(self, rhs: u32) -> Self { $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] + #[cfg_attr( + not(bootstrap), + 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 +1566,10 @@ pub fn wrapping_pow(self, mut exp: u32) -> Self { "::MIN, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +1597,10 @@ pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { "::MAX, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +1626,10 @@ pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) { $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +1797,10 @@ pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { ```"), #[inline] #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +1823,10 @@ pub const fn overflowing_neg(self) -> (Self, bool) { $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +1852,10 @@ pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) { $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +1884,10 @@ pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) { $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] + #[cfg_attr( + not(bootstrap), + 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 +2092,10 @@ pub fn rem_euclid(self, rhs: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_int_methods", since = "1.32.0"), + )] #[inline] #[rustc_inherit_overflow_checks] pub const fn abs(self) -> Self { @@ -2006,7 +2138,11 @@ pub const fn abs(self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_sign")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_sign"))] + #[cfg_attr( + not(bootstrap), + 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 +2163,10 @@ pub const fn signum(self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_int_methods", since = "1.32.0"), + )] #[inline] pub const fn is_positive(self) -> bool { self > 0 } } @@ -2045,6 +2185,10 @@ pub const fn is_positive(self) -> bool { self > 0 } $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_int_methods", since = "1.32.0"), + )] #[inline] pub const fn is_negative(self) -> bool { self < 0 } } @@ -2062,7 +2206,11 @@ pub const fn is_negative(self) -> bool { self < 0 } assert_eq!(bytes, ", $be_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn to_be_bytes(self) -> [u8; mem::size_of::()] { self.to_be().to_ne_bytes() @@ -2082,7 +2230,11 @@ pub const fn is_negative(self) -> bool { self < 0 } assert_eq!(bytes, ", $le_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn to_le_bytes(self) -> [u8; mem::size_of::()] { self.to_le().to_ne_bytes() @@ -2117,7 +2269,11 @@ pub const fn is_negative(self) -> bool { self < 0 } ); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn to_ne_bytes(self) -> [u8; mem::size_of::()] { // SAFETY: integers are plain old datatypes so we can always transmute them to @@ -2151,7 +2307,11 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn from_be_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_be(Self::from_ne_bytes(bytes)) @@ -2184,7 +2344,11 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn from_le_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_le(Self::from_ne_bytes(bytes)) @@ -2227,7 +2391,11 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn from_ne_bytes(bytes: [u8; mem::size_of::()]) -> Self { // SAFETY: integers are plain old datatypes so we can always transmute to them @@ -2321,6 +2489,10 @@ macro_rules! uint_impl { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] #[inline(always)] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_min_value", since = "1.32.0"), + )] pub const fn min_value() -> Self { 0 } } @@ -2338,6 +2510,10 @@ pub const fn min_value() -> Self { 0 } #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] #[inline(always)] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_max_value", since = "1.32.0"), + )] pub const fn max_value() -> Self { !0 } } @@ -2384,6 +2560,10 @@ pub fn from_str_radix(src: &str, radix: u32) -> Result { assert_eq!(n.count_ones(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2581,10 @@ pub const fn count_ones(self) -> u32 { ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_math", since = "1.32.0"), + )] #[inline] pub const fn count_zeros(self) -> u32 { (!self).count_ones() @@ -2420,6 +2604,10 @@ pub const fn count_zeros(self) -> u32 { assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2628,10 @@ pub const fn leading_zeros(self) -> u32 { assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2655,10 @@ pub const fn trailing_zeros(self) -> u32 { assert_eq!(n.rotate_left(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2685,10 @@ pub const fn rotate_left(self, n: u32) -> Self { assert_eq!(n.rotate_right(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2712,10 @@ pub const fn rotate_right(self, n: u32) -> Self { assert_eq!(m, ", $swapped, "); ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2736,10 @@ pub const fn swap_bytes(self) -> Self { assert_eq!(m, ", $reversed, "); ```"), #[stable(feature = "reverse_bits", since = "1.37.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_math", since = "1.32.0"), + )] #[inline] #[must_use] pub const fn reverse_bits(self) -> Self { @@ -2559,6 +2767,10 @@ pub const fn reverse_bits(self) -> Self { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2804,10 @@ pub const fn from_be(x: Self) -> Self { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2841,10 @@ pub const fn from_le(x: Self) -> Self { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +2878,10 @@ pub const fn to_be(self) -> Self { // or not to be? }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_math", since = "1.32.0"), + )] #[inline] pub const fn to_le(self) -> Self { #[cfg(target_endian = "little")] @@ -2963,7 +3187,11 @@ pub fn checked_pow(self, mut exp: u32) -> Option { #[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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_saturating_int_methods"))] + #[cfg_attr( + not(bootstrap), + 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 +3213,11 @@ pub const fn saturating_add(self, rhs: Self) -> Self { #[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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_saturating_int_methods"))] + #[cfg_attr( + not(bootstrap), + 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 +3289,10 @@ pub fn saturating_pow(self, exp: u32) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +3315,10 @@ pub const fn wrapping_add(self, rhs: Self) -> Self { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +3342,10 @@ pub const fn wrapping_sub(self, rhs: Self) -> Self { /// assert_eq!(25u8.wrapping_mul(12), 44); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +3475,10 @@ pub fn wrapping_rem_euclid(self, rhs: Self) -> Self { /// assert_eq!((-128i8).wrapping_neg(), -128); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] + #[cfg_attr( + not(bootstrap), + 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 +3505,10 @@ pub const fn wrapping_neg(self) -> Self { assert_eq!(1", stringify!($SelfT), ".wrapping_shl(128), 1);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[cfg_attr( + not(bootstrap), + 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 +3542,10 @@ pub const fn wrapping_shl(self, rhs: u32) -> Self { assert_eq!(128", stringify!($SelfT), ".wrapping_shr(128), 128);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] + #[cfg_attr( + not(bootstrap), + 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 +3615,10 @@ pub fn wrapping_pow(self, mut exp: u32) -> Self { assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +3647,10 @@ pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +3678,10 @@ pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) { /// assert_eq!(1_000_000_000u32.overflowing_mul(10), (1410065408, true)); /// ``` #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +3827,10 @@ pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { ```"), #[inline] #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +3854,10 @@ pub const fn overflowing_neg(self) -> (Self, bool) { assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(132), (0x10, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +3884,10 @@ pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) { assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(132), (0x1, true));", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] + #[cfg_attr( + not(bootstrap), + 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 +4053,10 @@ pub fn rem_euclid(self, rhs: Self) -> Self { assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +4168,11 @@ pub fn wrapping_next_power_of_two(self) -> Self { assert_eq!(bytes, ", $be_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn to_be_bytes(self) -> [u8; mem::size_of::()] { self.to_be().to_ne_bytes() @@ -3904,7 +4192,11 @@ pub fn wrapping_next_power_of_two(self) -> Self { assert_eq!(bytes, ", $le_bytes, "); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn to_le_bytes(self) -> [u8; mem::size_of::()] { self.to_le().to_ne_bytes() @@ -3939,7 +4231,11 @@ pub fn wrapping_next_power_of_two(self) -> Self { ); ```"), #[stable(feature = "int_to_from_bytes", since = "1.32.0")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn to_ne_bytes(self) -> [u8; mem::size_of::()] { // SAFETY: integers are plain old datatypes so we can always transmute them to @@ -3973,7 +4269,11 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn from_be_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_be(Self::from_ne_bytes(bytes)) @@ -4006,7 +4306,11 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn from_le_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_le(Self::from_ne_bytes(bytes)) @@ -4049,7 +4353,11 @@ 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")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_int_conversion"))] + #[cfg_attr( + not(bootstrap), + rustc_const_unstable(feature = "const_int_conversion", issue = "53718"), + )] #[inline] pub const fn from_ne_bytes(bytes: [u8; mem::size_of::()]) -> Self { // SAFETY: integers are plain old datatypes so we can always transmute to them diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 0ddfbd02aa5..46398dd2f82 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -530,6 +530,10 @@ pub const fn swap_bytes(self) -> Self { /// assert_eq!(m, Wrapping(-22016)); /// ``` #[stable(feature = "reverse_bits", since = "1.37.0")] + #[cfg_attr( + not(bootstrap), + 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..54ce2917a36 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -398,6 +398,7 @@ impl RangeInclusive { #[stable(feature = "inclusive_range_methods", since = "1.27.0")] #[inline] #[rustc_promotable] + #[cfg_attr(not(bootstrap), 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,10 @@ pub const fn new(start: Idx, end: Idx) -> Self { /// assert_eq!((3..=5).start(), &3); /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_inclusive_range_methods", since = "1.32.0"), + )] #[inline] pub const fn start(&self) -> &Idx { &self.start @@ -445,6 +450,10 @@ pub const fn start(&self) -> &Idx { /// assert_eq!((3..=5).end(), &5); /// ``` #[stable(feature = "inclusive_range_methods", since = "1.27.0")] + #[cfg_attr( + not(bootstrap), + 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/ptr/mod.rs b/src/libcore/ptr/mod.rs index 24ffa348329..33c23233fd1 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -198,6 +198,7 @@ unsafe fn real_drop_in_place(to_drop: &mut T) { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ptr_null", since = "1.32.0"))] pub const fn null() -> *const T { 0 as *const T } @@ -215,6 +216,7 @@ pub const fn null() -> *const T { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] +#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ptr_null", since = "1.32.0"))] pub const fn null_mut() -> *mut T { 0 as *mut T } @@ -1060,6 +1062,7 @@ pub fn is_null(self) -> bool { /// Casts to a pointer of another type. #[stable(feature = "ptr_cast", since = "1.38.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0"))] #[inline] pub const fn cast(self) -> *const U { self as _ @@ -1307,7 +1310,11 @@ pub fn wrapping_offset(self, count: isize) -> *const T /// } /// ``` #[unstable(feature = "ptr_offset_from", issue = "41079")] - #[rustc_const_unstable(feature = "const_ptr_offset_from")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_ptr_offset_from"))] + #[cfg_attr( + not(bootstrap), + 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 +1770,7 @@ pub fn is_null(self) -> bool { /// Casts to a pointer of another type. #[stable(feature = "ptr_cast", since = "1.38.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0"))] #[inline] pub const fn cast(self) -> *mut U { self as _ @@ -2049,7 +2057,11 @@ pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T> { /// } /// ``` #[unstable(feature = "ptr_offset_from", issue = "41079")] - #[rustc_const_unstable(feature = "const_ptr_offset_from")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_ptr_offset_from"))] + #[cfg_attr( + not(bootstrap), + 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..d1d97d7b332 100644 --- a/src/libcore/ptr/non_null.rs +++ b/src/libcore/ptr/non_null.rs @@ -66,6 +66,10 @@ impl NonNull { /// sentinel value. Types that lazily allocate must track initialization by /// some other means. #[stable(feature = "nonnull", since = "1.25.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_nonnull_dangling", since = "1.32.0"), + )] #[inline] pub const fn dangling() -> Self { unsafe { @@ -82,6 +86,10 @@ impl NonNull { /// /// `ptr` must be non-null. #[stable(feature = "nonnull", since = "1.25.0")] + #[cfg_attr( + not(bootstrap), + 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 +104,10 @@ pub fn new(ptr: *mut T) -> Option { /// Acquires the underlying `*mut` pointer. #[stable(feature = "nonnull", since = "1.25.0")] + #[cfg_attr( + not(bootstrap), + 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 +137,10 @@ pub unsafe fn as_mut(&mut self) -> &mut T { /// Casts to a pointer of another type. #[stable(feature = "nonnull_cast", since = "1.27.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_nonnull_cast", since = "1.32.0"), + )] #[inline] pub const fn cast(self) -> NonNull { unsafe { NonNull::new_unchecked(self.as_ptr() as *mut U) } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index c8fe9f98613..a8e500d256f 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -62,6 +62,7 @@ impl [T] { /// assert_eq!(a.len(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), 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,10 @@ pub const fn len(&self) -> usize { /// assert!(!a.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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 +381,10 @@ pub unsafe fn get_unchecked_mut(&mut self, index: I) -> &mut I::Output /// /// [`as_mut_ptr`]: #method.as_mut_ptr #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + 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..6d225a25f20 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -2090,6 +2090,7 @@ impl str { /// assert_eq!("ƒoo".chars().count(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), 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,10 @@ pub const fn len(&self) -> usize { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr( + not(bootstrap), + rustc_const_stable(feature = "const_str_is_empty", since = "1.32.0"), + )] pub const fn is_empty(&self) -> bool { self.len() == 0 } @@ -2166,6 +2171,7 @@ pub fn is_char_boundary(&self, index: usize) -> bool { /// assert_eq!(b"bors", bytes); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), 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 +2245,7 @@ pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] { /// let ptr = s.as_ptr(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), 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 diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 6e1aac00c7b..0b22ae69ac2 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")] + #[cfg_attr(not(bootstrap), 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 AtomicPtr { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_atomic_new", since = "1.32.0"))] pub const fn new(p: *mut T) -> AtomicPtr { AtomicPtr { p: UnsafeCell::new(p) } } @@ -1183,6 +1185,12 @@ macro_rules! atomic_int { $stable_access:meta, $stable_from:meta, $stable_nand:meta, + $const_stable:meta, + $const_stable_cxchg:meta, + $const_stable_debug:meta, + $const_stable_access:meta, + $const_stable_from:meta, + $const_stable_nand:meta, $stable_init_const:meta, $s_int_type:expr, $int_ref:expr, $extra_feature:expr, @@ -1258,6 +1266,7 @@ impl $atomic_type { ```"), #[inline] #[$stable] + #[cfg_attr(not(bootstrap), $const_stable)] pub const fn new(v: $int_type) -> Self { $atomic_type {v: UnsafeCell::new(v)} } @@ -1978,6 +1987,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2010,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2033,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2056,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2079,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2102,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2125,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2148,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", 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 +2171,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), "i128", "../../../std/primitive.i128.html", "#![feature(integer_atomics)]\n\n", @@ -2131,6 +2194,12 @@ pub fn as_mut_ptr(&self) -> *mut $int_type { unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), + rustc_const_unstable(feature = "const_integer_atomics", issue = "32976"), unstable(feature = "integer_atomics", issue = "32976"), "u128", "../../../std/primitive.u128.html", "#![feature(integer_atomics)]\n\n", @@ -2163,6 +2232,12 @@ macro_rules! ptr_width { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.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 +2255,12 @@ macro_rules! ptr_width { 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"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), + rustc_const_stable(feature = "const_integer_atomics", since = "1.34.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..c1e45f189b7 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")] + #[cfg_attr(not(bootstrap), 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] + #[cfg_attr(not(bootstrap), 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..7d04cfb5da5 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] + #[cfg_attr(not(bootstrap), 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 @@ pub fn new(secs: u64, nanos: u32) -> Duration { #[stable(feature = "duration", since = "1.3.0")] #[inline] #[rustc_promotable] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn from_secs(secs: u64) -> Duration { #[stable(feature = "duration", since = "1.3.0")] #[inline] #[rustc_promotable] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn from_millis(millis: u64) -> Duration { #[stable(feature = "duration_from_micros", since = "1.27.0")] #[inline] #[rustc_promotable] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn from_micros(micros: u64) -> Duration { #[stable(feature = "duration_extras", since = "1.27.0")] #[inline] #[rustc_promotable] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn from_nanos(nanos: u64) -> Duration { /// /// [`subsec_nanos`]: #method.subsec_nanos #[stable(feature = "duration", since = "1.3.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "duration", since = "1.32.0"))] #[inline] pub const fn as_secs(&self) -> u64 { self.secs @@ -272,6 +278,7 @@ pub const fn as_secs(&self) -> u64 { /// assert_eq!(duration.subsec_millis(), 432); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn subsec_millis(&self) -> u32 { /// assert_eq!(duration.subsec_micros(), 234_567); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn subsec_micros(&self) -> u32 { /// assert_eq!(duration.subsec_nanos(), 10_000_000); /// ``` #[stable(feature = "duration", since = "1.3.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "duration", since = "1.32.0"))] #[inline] pub const fn subsec_nanos(&self) -> u32 { self.nanos @@ -330,6 +339,7 @@ pub const fn subsec_nanos(&self) -> u32 { /// assert_eq!(duration.as_millis(), 5730); /// ``` #[stable(feature = "duration_as_u128", since = "1.33.0")] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn as_millis(&self) -> u128 { /// assert_eq!(duration.as_micros(), 5730023); /// ``` #[stable(feature = "duration_as_u128", since = "1.33.0")] + #[cfg_attr(not(bootstrap), 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 @@ pub const fn as_micros(&self) -> u128 { /// assert_eq!(duration.as_nanos(), 5730023852); /// ``` #[stable(feature = "duration_as_u128", since = "1.33.0")] + #[cfg_attr(not(bootstrap), 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 diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index bd47d41a785..51756084f24 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -19,7 +19,7 @@ use syntax::ast::{Attribute, CRATE_NODE_ID}; use syntax::errors::Applicability; use syntax::feature_gate::{feature_err, feature_err_issue}; -use syntax::attr::{self, Stability, Deprecation, RustcDeprecation}; +use syntax::attr::{self, Stability, Deprecation, RustcDeprecation, ConstStability}; use crate::ty::{self, TyCtxt}; use crate::util::nodemap::{FxHashSet, FxHashMap}; @@ -91,6 +91,7 @@ pub struct Index<'tcx> { /// This is mostly a cache, except the stabilities of local items /// are filled by the annotator. stab_map: FxHashMap, + const_stab_map: FxHashMap, depr_map: FxHashMap, /// Maps for each crate whether it is part of the staged API. @@ -123,8 +124,14 @@ fn annotate(&mut self, hir_id: HirId, attrs: &[Attribute], self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged API; \ use `#[rustc_deprecated]` instead"); } - if let Some(mut stab) = attr::find_stability(&self.tcx.sess.parse_sess, - attrs, item_sp) { + let (stab, const_stab) = attr::find_stability( + &self.tcx.sess.parse_sess, attrs, item_sp, + ); + if let Some(const_stab) = const_stab { + let const_stab = self.tcx.intern_const_stability(const_stab); + self.index.const_stab_map.insert(hir_id, const_stab); + } + if let Some(mut stab) = stab { // Error if prohibited, or can't inherit anything from a container. if kind == AnnotationKind::Prohibited || (kind == AnnotationKind::Container && @@ -193,6 +200,7 @@ fn annotate(&mut self, hir_id: HirId, attrs: &[Attribute], sym::unstable, sym::stable, sym::rustc_deprecated, sym::rustc_const_unstable, + sym::rustc_const_stable, ]; for attr in attrs { let name = attr.name_or_empty(); @@ -404,6 +412,7 @@ pub fn new(tcx: TyCtxt<'tcx>) -> Index<'tcx> { let mut index = Index { staged_api, stab_map: Default::default(), + const_stab_map: Default::default(), depr_map: Default::default(), active_features: Default::default(), }; @@ -445,9 +454,6 @@ pub fn new(tcx: TyCtxt<'tcx>) -> Index<'tcx> { }, feature: sym::rustc_private, rustc_depr: None, - const_stability: None, - promotable: false, - allow_const_fn_ptr: false, }); annotator.parent_stab = Some(stability); } @@ -465,6 +471,10 @@ pub fn local_stability(&self, id: HirId) -> Option<&'tcx Stability> { self.stab_map.get(&id).cloned() } + pub fn local_const_stability(&self, id: HirId) -> Option<&'tcx ConstStability> { + self.const_stab_map.get(&id).cloned() + } + pub fn local_deprecation_entry(&self, id: HirId) -> Option { self.depr_map.get(&id).cloned() } diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 538b13c79ce..cc02165f605 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -533,6 +533,7 @@ eval_always } query lookup_stability(_: DefId) -> Option<&'tcx attr::Stability> {} + query lookup_const_stability(_: DefId) -> Option<&'tcx attr::ConstStability> {} query lookup_deprecation_entry(_: DefId) -> Option {} query item_attrs(_: DefId) -> Lrc<[ast::Attribute]> {} } diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs index 268015a5624..0c87a53b3d0 100644 --- a/src/librustc/ty/constness.rs +++ b/src/librustc/ty/constness.rs @@ -30,7 +30,12 @@ pub fn is_const_fn(self, def_id: DefId) -> bool { /// Whether the `def_id` is an unstable const fn and what feature gate is necessary to enable it pub fn is_unstable_const_fn(self, def_id: DefId) -> Option { if self.is_const_fn_raw(def_id) { - self.lookup_stability(def_id)?.const_stability + let const_stab = self.lookup_const_stability(def_id)?; + if const_stab.level.is_unstable() { + Some(const_stab.feature) + } else { + None + } } else { None } @@ -83,15 +88,31 @@ pub fn is_min_const_fn(self, def_id: DefId) -> bool { } if self.features().staged_api { - // in order for a libstd function to be considered min_const_fn - // it needs to be stable and have no `rustc_const_unstable` attribute - match self.lookup_stability(def_id) { - // stable functions with unstable const fn aren't `min_const_fn` - Some(&attr::Stability { const_stability: Some(_), .. }) => false, - // unstable functions don't need to conform - Some(&attr::Stability { ref level, .. }) if level.is_unstable() => false, - // everything else needs to conform, because it would be callable from - // other `min_const_fn` functions + // In order for a libstd function to be considered min_const_fn + // it needs to be stable and have no `rustc_const_unstable` attribute. + match self.lookup_const_stability(def_id) { + // `rustc_const_unstable` functions don't need to conform. + Some(&attr::ConstStability { ref level, .. }) if level.is_unstable() => false, + None => if let Some(stab) = self.lookup_stability(def_id) { + if stab.level.is_stable() { + self.sess.span_err( + self.def_span(def_id), + "stable const functions must have either `rustc_const_stable` or \ + `rustc_const_unstable` attribute", + ); + // While we errored above, because we don't know if we need to conform, we + // err on the "safe" side and require min_const_fn. + true + } else { + // Unstable functions need not conform to min const fn. + false + } + } else { + // Unstable functions or internal functions need not conform to min const fn. + false + }, + // Everything else needs to conform, because it would be callable from + // other `min_const_fn` functions. _ => true, } } else { @@ -188,7 +209,7 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { } fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool { - tcx.is_const_fn(def_id) && match tcx.lookup_stability(def_id) { + tcx.is_const_fn(def_id) && match tcx.lookup_const_stability(def_id) { Some(stab) => { if cfg!(debug_assertions) && stab.promotable { let sig = tcx.fn_sig(def_id); @@ -207,7 +228,7 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool { tcx.is_const_fn(def_id) && - tcx.lookup_stability(def_id) + tcx.lookup_const_stability(def_id) .map(|stab| stab.allow_const_fn_ptr).unwrap_or(false) } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index f7e422b0403..595ea40b2ff 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1066,8 +1066,12 @@ pub struct GlobalCtxt<'tcx> { /// Data layout specification for the current target. pub data_layout: TargetDataLayout, + /// `#[stable]` and `#[unstable]` attributes stability_interner: ShardedHashMap<&'tcx attr::Stability, ()>, + /// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes + const_stability_interner: ShardedHashMap<&'tcx attr::ConstStability, ()>, + /// Stores the value of constants (and deduplicates the actual memory) allocation_interner: ShardedHashMap<&'tcx Allocation, ()>, @@ -1129,6 +1133,12 @@ pub fn intern_stability(self, stab: attr::Stability) -> &'tcx attr::Stability { }) } + pub fn intern_const_stability(self, stab: attr::ConstStability) -> &'tcx attr::ConstStability { + self.const_stability_interner.intern(stab, |stab| { + self.arena.alloc(stab) + }) + } + pub fn intern_layout(self, layout: LayoutDetails) -> &'tcx LayoutDetails { self.layout_interner.intern(layout, |layout| { self.arena.alloc(layout) @@ -1269,6 +1279,7 @@ pub fn create_global_ctxt( data_layout, layout_interner: Default::default(), stability_interner: Default::default(), + const_stability_interner: Default::default(), allocation_interner: Default::default(), alloc_map: Lock::new(interpret::AllocMap::new()), output_filenames: Arc::new(output_filenames.clone()), @@ -2058,6 +2069,7 @@ pub fn print_debug_stats(self) { println!("InternalSubsts interner: #{}", self.interners.substs.len()); println!("Region interner: #{}", self.interners.region.len()); println!("Stability interner: #{}", self.stability_interner.len()); + println!("Const Stability interner: #{}", self.const_stability_interner.len()); println!("Allocation interner: #{}", self.allocation_interner.len()); println!("Layout interner: #{}", self.layout_interner.len()); } @@ -2992,6 +3004,11 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { let id = tcx.hir().definitions().def_index_to_hir_id(id.index); tcx.stability().local_stability(id) }; + providers.lookup_const_stability = |tcx, id| { + assert_eq!(id.krate, LOCAL_CRATE); + let id = tcx.hir().definitions().def_index_to_hir_id(id.index); + tcx.stability().local_const_stability(id) + }; providers.lookup_deprecation_entry = |tcx, id| { assert_eq!(id.krate, LOCAL_CRATE); let id = tcx.hir().definitions().def_index_to_hir_id(id.index); diff --git a/src/librustc_feature/builtin_attrs.rs b/src/librustc_feature/builtin_attrs.rs index 0db2401aaea..0a4fb8a224e 100644 --- a/src/librustc_feature/builtin_attrs.rs +++ b/src/librustc_feature/builtin_attrs.rs @@ -346,6 +346,8 @@ macro_rules! experimental { ), // FIXME(#14407) ungated!(rustc_const_unstable, Whitelisted, template!(List: r#"feature = "name""#)), + // FIXME(#14407) + ungated!(rustc_const_stable, Whitelisted, template!(List: r#"feature = "name""#)), gated!( allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), "allow_internal_unstable side-steps feature gating and stability checks", diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 0107a22772f..a1f95e35cbe 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -852,6 +852,10 @@ fn get_stability(&self, id: DefIndex) -> Option { } } + fn get_const_stability(&self, id: DefIndex) -> Option { + self.root.per_def.const_stability.get(self, id).map(|stab| stab.decode(self)) + } + fn get_deprecation(&self, id: DefIndex) -> Option { self.root.per_def.deprecation.get(self, id) .filter(|_| !self.is_proc_macro(id)) diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index 13db9a6fef9..4a6b25930c8 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -134,6 +134,9 @@ fn into_args(self) -> (DefId, DefId) { (self.0.as_def_id(), self.1) } lookup_stability => { cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s)) } + lookup_const_stability => { + cdata.get_const_stability(def_id.index).map(|s| tcx.intern_const_stability(s)) + } lookup_deprecation_entry => { cdata.get_deprecation(def_id.index).map(DeprecationEntry::external) } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index fb70e10c84f..c1562a77342 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -866,6 +866,7 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) { record!(self.per_def.span[def_id] <- ast_item.span); record!(self.per_def.attributes[def_id] <- &ast_item.attrs); self.encode_stability(def_id); + self.encode_const_stability(def_id); self.encode_deprecation(def_id); match trait_item.kind { ty::AssocKind::Const | @@ -946,6 +947,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) { record!(self.per_def.span[def_id] <- ast_item.span); record!(self.per_def.attributes[def_id] <- &ast_item.attrs); self.encode_stability(def_id); + self.encode_const_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); if impl_item.kind == ty::AssocKind::Method { @@ -1025,6 +1027,13 @@ fn encode_stability(&mut self, def_id: DefId) { } } + fn encode_const_stability(&mut self, def_id: DefId) { + debug!("EncodeContext::encode_const_stability({:?})", def_id); + if let Some(stab) = self.tcx.lookup_const_stability(def_id) { + record!(self.per_def.const_stability[def_id] <- stab) + } + } + fn encode_deprecation(&mut self, def_id: DefId) { debug!("EncodeContext::encode_deprecation({:?})", def_id); if let Some(depr) = self.tcx.lookup_deprecation(def_id) { @@ -1186,6 +1195,7 @@ fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item) { _ => {} } self.encode_stability(def_id); + self.encode_const_stability(def_id); self.encode_deprecation(def_id); match item.kind { hir::ItemKind::Static(..) | @@ -1545,6 +1555,7 @@ fn encode_info_for_foreign_item( record!(self.per_def.span[def_id] <- nitem.span); record!(self.per_def.attributes[def_id] <- &nitem.attrs); self.encode_stability(def_id); + self.encode_const_stability(def_id); self.encode_deprecation(def_id); self.encode_item_type(def_id); if let hir::ForeignItemKind::Fn(..) = nitem.kind { diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index 5abae429373..e13edc2d621 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -261,6 +261,7 @@ fn encode(&self, buf: &mut Encoder) -> LazyPerDefTables<'tcx> { attributes: Table>, children: Table>, stability: Table>, + const_stability: Table>, deprecation: Table>, ty: Table)>, fn_sig: Table)>, diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 6dcda986310..14ca0423d8b 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -1065,7 +1065,8 @@ pub fn from_bytes_with_nul(bytes: &[u8]) /// ``` #[inline] #[stable(feature = "cstr_from_bytes", since = "1.10.0")] - #[rustc_const_unstable(feature = "const_cstr_unchecked")] + #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_cstr_unchecked"))] + #[cfg_attr(not(bootstrap), rustc_const_unstable(feature = "const_cstr_unchecked", issue = "0"))] pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr { &*(bytes as *const [u8] as *const CStr) } @@ -1119,6 +1120,7 @@ pub fn from_bytes_with_nul(bytes: &[u8]) /// [`CString`]: struct.CString.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0"))] pub const fn as_ptr(&self) -> *const c_char { self.inner.as_ptr() } diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index e51a9b62449..7d69f8f4b8d 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -319,6 +319,7 @@ impl Ipv4Addr { /// let addr = Ipv4Addr::new(127, 0, 0, 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ipv4", since = "1.32.0"))] pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { // FIXME: should just be u32::from_be_bytes([a, b, c, d]), // once that method is no longer rustc_const_unstable @@ -406,6 +407,7 @@ pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false); /// ``` #[stable(feature = "ip_shared", since = "1.12.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ipv4", since = "1.32.0"))] pub const fn is_unspecified(&self) -> bool { self.inner.s_addr == 0 } @@ -1015,6 +1017,7 @@ impl Ipv6Addr { /// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ipv6", since = "1.32.0"))] pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { Ipv6Addr { @@ -1480,6 +1483,7 @@ pub fn to_ipv4(&self) -> Option { /// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); /// ``` #[stable(feature = "ipv6_to_octets", since = "1.12.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_ipv6", since = "1.32.0"))] pub const fn octets(&self) -> [u8; 16] { self.inner.s6_addr } diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index e8e395247f9..d8df09071cd 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -188,6 +188,7 @@ struct WaiterQueue<'a> { impl Once { /// Creates a new `Once` value. #[stable(feature = "once_new", since = "1.2.0")] + #[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_once_new", since = "1.32.0"))] pub const fn new() -> Once { Once { state_and_queue: AtomicUsize::new(INCOMPLETE), _marker: marker::PhantomData } } diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 3c10f27b60a..a37b27f67bc 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -120,17 +120,21 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op }) } -/// Represents the #[stable], #[unstable], #[rustc_{deprecated,const_unstable}] attributes. +/// Represents the #[stable], #[unstable], #[rustc_deprecated] attributes. #[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)] pub struct Stability { pub level: StabilityLevel, pub feature: Symbol, pub rustc_depr: Option, - /// `None` means the function is stable but needs to be a stable const fn, too - /// `Some` contains the feature gate required to be able to use the function - /// as const fn - pub const_stability: Option, +} + +/// Represents the #[rustc_const_unstable] and #[rustc_const_stable] attributes. +#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, + PartialEq, Eq, Hash, HashStable_Generic)] +pub struct ConstStability { + pub level: StabilityLevel, + pub feature: Symbol, /// whether the function has a `#[rustc_promotable]` attribute pub promotable: bool, /// whether the function has a `#[rustc_allow_const_fn_ptr]` attribute @@ -186,21 +190,21 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool /// Collects stability info from all stability attributes in `attrs`. /// Returns `None` if no stability attributes are found. pub fn find_stability(sess: &ParseSess, attrs: &[Attribute], - item_sp: Span) -> Option { + item_sp: Span) -> (Option, Option) { find_stability_generic(sess, attrs.iter(), item_sp) } fn find_stability_generic<'a, I>(sess: &ParseSess, attrs_iter: I, item_sp: Span) - -> Option + -> (Option, Option) where I: Iterator { use StabilityLevel::*; let mut stab: Option = None; let mut rustc_depr: Option = None; - let mut rustc_const_unstable: Option = None; + let mut const_stab: Option = None; let mut promotable = false; let mut allow_const_fn_ptr = false; let diagnostic = &sess.span_diagnostic; @@ -209,6 +213,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, if ![ sym::rustc_deprecated, sym::rustc_const_unstable, + sym::rustc_const_stable, sym::unstable, sym::stable, sym::rustc_promotable, @@ -287,7 +292,8 @@ macro_rules! get_meta { } } - match meta.name_or_empty() { + let meta_name = meta.name_or_empty(); + match meta_name { sym::rustc_deprecated => { if rustc_depr.is_some() { span_err!(diagnostic, item_sp, E0540, @@ -315,23 +321,12 @@ macro_rules! get_meta { } } } - sym::rustc_const_unstable => { - if rustc_const_unstable.is_some() { - span_err!(diagnostic, item_sp, E0553, - "multiple rustc_const_unstable attributes"); - continue 'outer - } - - get_meta!(feature); - if let Some(feature) = feature { - rustc_const_unstable = Some(feature); - } else { - span_err!(diagnostic, attr.span, E0629, "missing 'feature'"); - continue - } - } + sym::rustc_const_unstable | sym::unstable => { - if stab.is_some() { + if meta_name == sym::unstable && stab.is_some() { + handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels); + break + } else if meta_name == sym::rustc_const_unstable && const_stab.is_some() { handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels); break } @@ -398,18 +393,25 @@ macro_rules! get_meta { } } }; - stab = Some(Stability { - level: Unstable { - reason, - issue, - is_soft, - }, - feature, - rustc_depr: None, - const_stability: None, - promotable: false, - allow_const_fn_ptr: false, - }) + let level = Unstable { + reason, + issue, + is_soft, + }; + if sym::unstable == meta_name { + stab = Some(Stability { + level, + feature, + rustc_depr: None, + }); + } else { + const_stab = Some(ConstStability { + level, + feature, + promotable: false, + allow_const_fn_ptr: false, + }); + } } (None, _, _) => { handle_errors(sess, attr.span, AttrError::MissingFeature); @@ -421,8 +423,12 @@ macro_rules! get_meta { } } } + sym::rustc_const_stable | sym::stable => { - if stab.is_some() { + if meta_name == sym::stable && stab.is_some() { + handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels); + break + } else if meta_name == sym::rustc_const_stable &&const_stab.is_some() { handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels); break } @@ -464,16 +470,21 @@ macro_rules! get_meta { match (feature, since) { (Some(feature), Some(since)) => { - stab = Some(Stability { - level: Stable { - since, - }, - feature, - rustc_depr: None, - const_stability: None, - promotable: false, - allow_const_fn_ptr: false, - }) + let level = Stable { since }; + if sym::stable == meta_name { + stab = Some(Stability { + level, + feature, + rustc_depr: None, + }); + } else { + const_stab = Some(ConstStability { + level, + feature, + promotable: false, + allow_const_fn_ptr: false, + }); + } } (None, _) => { handle_errors(sess, attr.span, AttrError::MissingFeature); @@ -501,30 +512,20 @@ macro_rules! get_meta { } } - // Merge the const-unstable info into the stability info - if let Some(feature) = rustc_const_unstable { - if let Some(ref mut stab) = stab { - stab.const_stability = Some(feature); - } else { - span_err!(diagnostic, item_sp, E0630, - "rustc_const_unstable attribute must be paired with \ - either stable or unstable attribute"); - } - } - // Merge the const-unstable info into the stability info if promotable || allow_const_fn_ptr { - if let Some(ref mut stab) = stab { + if let Some(ref mut stab) = const_stab { stab.promotable = promotable; stab.allow_const_fn_ptr = allow_const_fn_ptr; } else { span_err!(diagnostic, item_sp, E0717, "rustc_promotable and rustc_allow_const_fn_ptr attributes \ - must be paired with either stable or unstable attribute"); + must be paired with either a rustc_const_unstable or a rustc_const_stable \ + attribute"); } } - stab + (stab, const_stab) } pub fn find_crate_name(attrs: &[Attribute]) -> Option { diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index a4449ca5b1d..c7dce93f91b 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -775,6 +775,10 @@ pub fn new( } let is_builtin = attr::contains_name(attrs, sym::rustc_builtin_macro); + let (stability, const_stability) = attr::find_stability(&sess, attrs, span); + if const_stability.is_some() { + sess.span_diagnostic.span_err(span, "macros can't have const stability attributes"); + } SyntaxExtension { kind, @@ -782,7 +786,7 @@ pub fn new( allow_internal_unstable, allow_internal_unsafe: attr::contains_name(attrs, sym::allow_internal_unsafe), local_inner_macros, - stability: attr::find_stability(&sess, attrs, span), + stability, deprecation: attr::find_deprecation(&sess, attrs, span), helper_attrs, edition, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 92de56bd09a..c7e4182de6b 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -605,6 +605,7 @@ rustc_builtin_macro, rustc_clean, rustc_const_unstable, + rustc_const_stable, rustc_conversion_suggestion, rustc_def_path, rustc_deprecated, diff --git a/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs b/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs index e54cbb09804..b1d5440b41a 100644 --- a/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs +++ b/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs @@ -7,6 +7,7 @@ #[rustc_promotable] #[stable(since="1.0.0", feature = "mep")] +#[rustc_const_stable(since="1.0.0", feature = "mep")] #[inline] pub const fn foo() -> usize { 22 } @@ -15,6 +16,7 @@ pub const fn foo() -> usize { 22 } impl Foo { #[stable(since="1.0.0", feature = "mep")] + #[rustc_const_stable(feature = "mep", since = "1.0.0")] #[inline] #[rustc_promotable] pub const fn foo() -> usize { 22 } diff --git a/src/test/ui/consts/const-eval/auxiliary/stability.rs b/src/test/ui/consts/const-eval/auxiliary/stability.rs index f32e35d82af..830db55207f 100644 --- a/src/test/ui/consts/const-eval/auxiliary/stability.rs +++ b/src/test/ui/consts/const-eval/auxiliary/stability.rs @@ -7,5 +7,5 @@ #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature="foo")] +#[rustc_const_unstable(feature="foo", issue = "0")] pub const fn foo() -> u32 { 42 } diff --git a/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.rs b/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.rs index ea9c365410d..c4b89b50bc4 100644 --- a/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.rs +++ b/src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.rs @@ -7,7 +7,7 @@ #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature="foo")] +#[rustc_const_unstable(feature="foo", issue = "0")] const fn foo() -> u32 { 42 } fn meh() -> u32 { 42 } diff --git a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.rs b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.rs index 3992607c387..937aae1a8e3 100644 --- a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.rs +++ b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.rs @@ -1,10 +1,12 @@ #![feature(rustc_attrs, staged_api)] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(since="1.0.0", feature = "mep")] const fn error(_: fn()) {} //~ ERROR function pointers in const fn are unstable #[stable(feature = "rust1", since = "1.0.0")] #[rustc_allow_const_fn_ptr] +#[rustc_const_stable(since="1.0.0", feature = "mep")] const fn compiles(_: fn()) {} fn main() {} diff --git a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr index 6228b012dde..0ede4229ade 100644 --- a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr +++ b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr @@ -1,5 +1,5 @@ error[E0723]: function pointers in const fn are unstable - --> $DIR/allow_const_fn_ptr.rs:4:16 + --> $DIR/allow_const_fn_ptr.rs:5:16 | LL | const fn error(_: fn()) {} | ^ diff --git a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs index 1d8b95ab1a2..7aa9bd7e2dc 100644 --- a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs +++ b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs @@ -5,6 +5,7 @@ #[stable(feature = "rust1", since = "1.0.0")] #[rustc_allow_const_fn_ptr] +#[rustc_const_stable(since="1.0.0", feature = "mep")] const fn takes_fn_ptr(_: fn()) {} const FN: fn() = || (); diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs index 6d53da50b3f..97e467aece2 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs @@ -7,10 +7,11 @@ #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature="foo")] +#[rustc_const_unstable(feature="foo", issue = "0")] const fn foo() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const fn bar() -> u32 { foo() } //~ ERROR can only call other `const fn` @@ -18,10 +19,12 @@ const fn bar() -> u32 { foo() } //~ ERROR can only call other `const fn` const fn foo2() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const fn bar2() -> u32 { foo2() } //~ ERROR can only call other `const fn` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // conformity is required, even with `const_fn` feature gate const fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` operations @@ -30,6 +33,7 @@ const fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and ` const fn foo2_gated() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `const fn` diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr index 0af5bdca815..1da9b41aa59 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr @@ -1,5 +1,5 @@ error[E0723]: can only call other `const fn` within a `const fn`, but `const foo` is not stable as `const fn` - --> $DIR/min_const_fn_libstd_stability.rs:15:25 + --> $DIR/min_const_fn_libstd_stability.rs:16:25 | LL | const fn bar() -> u32 { foo() } | ^^^^^ @@ -8,7 +8,7 @@ LL | const fn bar() -> u32 { foo() } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn` - --> $DIR/min_const_fn_libstd_stability.rs:22:26 + --> $DIR/min_const_fn_libstd_stability.rs:24:26 | LL | const fn bar2() -> u32 { foo2() } | ^^^^^^ @@ -17,7 +17,7 @@ LL | const fn bar2() -> u32 { foo2() } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn - --> $DIR/min_const_fn_libstd_stability.rs:26:26 + --> $DIR/min_const_fn_libstd_stability.rs:29:26 | LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 } | ^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn` - --> $DIR/min_const_fn_libstd_stability.rs:34:32 + --> $DIR/min_const_fn_libstd_stability.rs:38:32 | LL | const fn bar2_gated() -> u32 { foo2_gated() } | ^^^^^^^^^^^^ diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs index f1f15a34c9e..102b3801441 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs @@ -7,10 +7,11 @@ #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature="foo")] +#[rustc_const_unstable(feature="foo", issue = "0")] const unsafe fn foo() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const unsafe fn bar() -> u32 { unsafe { foo() } } //~ ERROR can only call other `const fn` @@ -18,10 +19,12 @@ const unsafe fn foo2() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR can only call other `const fn` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // conformity is required, even with `const_fn` feature gate const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` op @@ -30,6 +33,7 @@ const unsafe fn foo2_gated() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } } //~^ ERROR can only call other `const fn` diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr index bc6f8c59606..ae92602d45f 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr @@ -1,5 +1,5 @@ error[E0723]: can only call other `const fn` within a `const fn`, but `const foo` is not stable as `const fn` - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:15:41 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:16:41 | LL | const unsafe fn bar() -> u32 { unsafe { foo() } } | ^^^^^ @@ -8,7 +8,7 @@ LL | const unsafe fn bar() -> u32 { unsafe { foo() } } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn` - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:22:42 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:24:42 | LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } } | ^^^^^^ @@ -17,7 +17,7 @@ LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:26:33 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:29:33 | LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 } | ^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn` - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:34:48 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:38:48 | LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } } | ^^^^^^^^^^^^ diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs index 2ac9e32e4a0..121177f8366 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs @@ -7,10 +7,11 @@ #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature="foo")] +#[rustc_const_unstable(feature="foo", issue = "0")] const fn foo() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const unsafe fn bar() -> u32 { foo() } //~ ERROR can only call other `const fn` @@ -18,6 +19,7 @@ const fn foo() -> u32 { 42 } const fn foo2() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `const fn` @@ -26,6 +28,7 @@ const fn foo2() -> u32 { 42 } const fn foo2_gated() -> u32 { 42 } #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] // can't call non-min_const_fn const unsafe fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `const fn` diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr index a14fd740c67..a0db74cfad6 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr @@ -1,5 +1,5 @@ error[E0723]: can only call other `const fn` within a `const fn`, but `const foo` is not stable as `const fn` - --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:15:32 + --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:16:32 | LL | const unsafe fn bar() -> u32 { foo() } | ^^^^^ @@ -8,7 +8,7 @@ LL | const unsafe fn bar() -> u32 { foo() } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn` - --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:22:33 + --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:24:33 | LL | const unsafe fn bar2() -> u32 { foo2() } | ^^^^^^ @@ -17,7 +17,7 @@ LL | const unsafe fn bar2() -> u32 { foo2() } = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn` - --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:30:39 + --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:33:39 | LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() } | ^^^^^^^^^^^^ diff --git a/src/test/ui/consts/unstable-const-fn-in-libcore.rs b/src/test/ui/consts/unstable-const-fn-in-libcore.rs index cad1516fc78..655ad7b548a 100644 --- a/src/test/ui/consts/unstable-const-fn-in-libcore.rs +++ b/src/test/ui/consts/unstable-const-fn-in-libcore.rs @@ -14,7 +14,7 @@ enum Opt { } impl Opt { - #[rustc_const_unstable(feature = "foo")] + #[rustc_const_unstable(feature = "foo", issue = "0")] #[stable(feature = "rust1", since = "1.0.0")] const fn unwrap_or_else T>(self, f: F) -> T { //~^ ERROR destructors cannot be evaluated at compile-time diff --git a/src/test/ui/feature-gate/allow-features-empty.stderr b/src/test/ui/feature-gate/allow-features-empty.stderr index a87d1058503..f88b3ea0a60 100644 --- a/src/test/ui/feature-gate/allow-features-empty.stderr +++ b/src/test/ui/feature-gate/allow-features-empty.stderr @@ -1,21 +1,15 @@ -error[E0725]: the feature `rustc_const_unstable` is not in the list of allowed features - --> $DIR/allow-features-empty.rs:4:12 - | -LL | #![feature(rustc_const_unstable)] - | ^^^^^^^^^^^^^^^^^^^^ - error[E0725]: the feature `lang_items` is not in the list of allowed features - --> $DIR/allow-features-empty.rs:6:12 + --> $DIR/allow-features-empty.rs:4:12 | LL | #![feature(lang_items)] | ^^^^^^^^^^ error[E0725]: the feature `unknown_stdlib_feature` is not in the list of allowed features - --> $DIR/allow-features-empty.rs:8:12 + --> $DIR/allow-features-empty.rs:6:12 | LL | #![feature(unknown_stdlib_feature)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0725`. diff --git a/src/test/ui/feature-gate/allow-features.stderr b/src/test/ui/feature-gate/allow-features.stderr index 157dddf06ad..9caf48dd138 100644 --- a/src/test/ui/feature-gate/allow-features.stderr +++ b/src/test/ui/feature-gate/allow-features.stderr @@ -1,15 +1,9 @@ -error[E0725]: the feature `rustc_const_unstable` is not in the list of allowed features - --> $DIR/allow-features.rs:4:12 - | -LL | #![feature(rustc_const_unstable)] - | ^^^^^^^^^^^^^^^^^^^^ - error[E0725]: the feature `unknown_stdlib_feature` is not in the list of allowed features - --> $DIR/allow-features.rs:8:12 + --> $DIR/allow-features.rs:6:12 | LL | #![feature(unknown_stdlib_feature)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0725`. diff --git a/src/test/ui/feature-gates/feature-gate-rustc_const_unstable.stderr b/src/test/ui/feature-gates/feature-gate-rustc_const_unstable.stderr index d7b7cf72a26..9df926dcf90 100644 --- a/src/test/ui/feature-gates/feature-gate-rustc_const_unstable.stderr +++ b/src/test/ui/feature-gates/feature-gate-rustc_const_unstable.stderr @@ -1,11 +1,9 @@ -error[E0658]: the `#[rustc_const_unstable]` attribute is an internal feature - --> $DIR/feature-gate-rustc_const_unstable.rs:8:1 +error[E0734]: stability attributes may not be used outside of the standard library + --> $DIR/feature-gate-rustc_const_unstable.rs:5:1 | LL | #[rustc_const_unstable(feature="fzzzzzt")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(rustc_const_unstable)]` to the crate attributes to enable error: aborting due to previous error -For more information about this error, try `rustc --explain E0658`. +For more information about this error, try `rustc --explain E0734`. diff --git a/src/test/ui/invalid_const_promotion.rs b/src/test/ui/invalid_const_promotion.rs index 91115ef74b8..5d7664cefb3 100644 --- a/src/test/ui/invalid_const_promotion.rs +++ b/src/test/ui/invalid_const_promotion.rs @@ -22,6 +22,7 @@ // of the const fn kicks in, causing a different code path in the // compiler to be executed (see PR #66294). #[stable(feature = "rustc", since = "1.0.0")] +#[rustc_const_stable(feature = "rustc", since = "1.0.0")] #[rustc_promotable] const fn bar(_: bool) -> usize { 0 - 1 } diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity.rs b/src/test/ui/stability-attribute/stability-attribute-sanity.rs index fc96d44bbb7..2e3d790d2d8 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity.rs +++ b/src/test/ui/stability-attribute/stability-attribute-sanity.rs @@ -60,11 +60,10 @@ fn multiple3() { } #[stable(feature = "a", since = "b")] #[rustc_deprecated(since = "b", reason = "text")] #[rustc_deprecated(since = "b", reason = "text")] -#[rustc_const_unstable(feature = "c")] -#[rustc_const_unstable(feature = "d")] +#[rustc_const_unstable(feature = "c", issue = "0")] +#[rustc_const_unstable(feature = "d", issue = "0")] //~ ERROR multiple stability levels pub const fn multiple4() { } //~ ERROR multiple rustc_deprecated attributes [E0540] //~^ ERROR Invalid stability or deprecation version found -//~| ERROR multiple rustc_const_unstable attributes #[rustc_deprecated(since = "a", reason = "text")] fn deprecated_without_unstable_or_stable() { } diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr index 4b7ec821f45..552e078f45f 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity.stderr @@ -88,11 +88,11 @@ error[E0540]: multiple rustc_deprecated attributes LL | pub const fn multiple4() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0553]: multiple rustc_const_unstable attributes - --> $DIR/stability-attribute-sanity.rs:65:1 +error[E0544]: multiple stability levels + --> $DIR/stability-attribute-sanity.rs:64:1 | -LL | pub const fn multiple4() { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_const_unstable(feature = "d", issue = "0")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Invalid stability or deprecation version found --> $DIR/stability-attribute-sanity.rs:65:1 @@ -101,7 +101,7 @@ LL | pub const fn multiple4() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0549]: rustc_deprecated attribute must be paired with either stable or unstable attribute - --> $DIR/stability-attribute-sanity.rs:70:1 + --> $DIR/stability-attribute-sanity.rs:69:1 | LL | fn deprecated_without_unstable_or_stable() { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index 41c4b618e60..311914ef23b 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -43,8 +43,6 @@ "E0523", "E0554", "E0570", - "E0629", - "E0630", "E0640", "E0717", "E0727", -- 2.44.0