Skip to content

Commit 5e17e39

Browse files
committed
Require stable/unstable annotations for the constness of all stable functions with a const modifier
1 parent d75c753 commit 5e17e39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+754
-155
lines changed

src/liballoc/collections/linked_list.rs

+4
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ impl<T> LinkedList<T> {
275275
/// let list: LinkedList<u32> = LinkedList::new();
276276
/// ```
277277
#[inline]
278+
#[cfg_attr(
279+
not(bootstrap),
280+
rustc_const_stable(feature = "const_linked_list_new", since = "1.32.0"),
281+
)]
278282
#[stable(feature = "rust1", since = "1.0.0")]
279283
pub const fn new() -> Self {
280284
LinkedList {

src/liballoc/string.rs

+4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ impl String {
367367
/// let s = String::new();
368368
/// ```
369369
#[inline]
370+
#[cfg_attr(
371+
not(bootstrap),
372+
rustc_const_stable(feature = "const_string_new", since = "1.32.0"),
373+
)]
370374
#[stable(feature = "rust1", since = "1.0.0")]
371375
pub const fn new() -> String {
372376
String { vec: Vec::new() }

src/liballoc/vec.rs

+4
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ impl<T> Vec<T> {
315315
/// let mut vec: Vec<i32> = Vec::new();
316316
/// ```
317317
#[inline]
318+
#[cfg_attr(
319+
not(bootstrap),
320+
rustc_const_stable(feature = "const_vec_new", since = "1.32.0"),
321+
)]
318322
#[stable(feature = "rust1", since = "1.0.0")]
319323
pub const fn new() -> Vec<T> {
320324
Vec {

src/libcore/alloc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl Layout {
100100
/// This function is unsafe as it does not verify the preconditions from
101101
/// [`Layout::from_size_align`](#method.from_size_align).
102102
#[stable(feature = "alloc_layout", since = "1.28.0")]
103+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "alloc_layout", since = "1.28.0"))]
103104
#[inline]
104105
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
105106
Layout { size_: size, align_: NonZeroUsize::new_unchecked(align) }

src/libcore/any.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ impl TypeId {
423423
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
424424
/// ```
425425
#[stable(feature = "rust1", since = "1.0.0")]
426-
#[rustc_const_unstable(feature="const_type_id")]
426+
#[cfg_attr(bootstrap, rustc_const_unstable(feature="const_type_id"))]
427+
#[cfg_attr(not(bootstrap), rustc_const_unstable(feature="const_type_id", issue = "41875"))]
427428
pub const fn of<T: ?Sized + 'static>() -> TypeId {
428429
TypeId {
429430
#[cfg(bootstrap)]
@@ -461,7 +462,8 @@ impl TypeId {
461462
/// );
462463
/// ```
463464
#[stable(feature = "type_name", since = "1.38.0")]
464-
#[rustc_const_unstable(feature = "const_type_name")]
465+
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_type_name"))]
466+
#[cfg_attr(not(bootstrap), rustc_const_unstable(feature = "const_type_name", issue = "63084"))]
465467
pub const fn type_name<T: ?Sized>() -> &'static str {
466468
intrinsics::type_name::<T>()
467469
}
@@ -499,7 +501,8 @@ pub const fn type_name<T: ?Sized>() -> &'static str {
499501
/// println!("{}", type_name_of_val(&y));
500502
/// ```
501503
#[unstable(feature = "type_name_of_val", issue = "66359")]
502-
#[rustc_const_unstable(feature = "const_type_name")]
504+
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_type_name"))]
505+
#[cfg_attr(not(bootstrap), rustc_const_unstable(feature = "const_type_name", issue = "63084"))]
503506
pub const fn type_name_of_val<T: ?Sized>(val: &T) -> &'static str {
504507
let _ = val;
505508
type_name::<T>()

src/libcore/cell.rs

+11
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<T> Cell<T> {
324324
/// let c = Cell::new(5);
325325
/// ```
326326
#[stable(feature = "rust1", since = "1.0.0")]
327+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_cell_new", since = "1.32.0"))]
327328
#[inline]
328329
pub const fn new(value: T) -> Cell<T> {
329330
Cell {
@@ -469,6 +470,7 @@ impl<T: ?Sized> Cell<T> {
469470
/// ```
470471
#[inline]
471472
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
473+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_cell_as_ptr", since = "1.32.0"))]
472474
pub const fn as_ptr(&self) -> *mut T {
473475
self.value.get()
474476
}
@@ -649,6 +651,7 @@ impl<T> RefCell<T> {
649651
/// let c = RefCell::new(5);
650652
/// ```
651653
#[stable(feature = "rust1", since = "1.0.0")]
654+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_refcell_new", since = "1.32.0"))]
652655
#[inline]
653656
pub const fn new(value: T) -> RefCell<T> {
654657
RefCell {
@@ -1501,6 +1504,10 @@ impl<T> UnsafeCell<T> {
15011504
/// let uc = UnsafeCell::new(5);
15021505
/// ```
15031506
#[stable(feature = "rust1", since = "1.0.0")]
1507+
#[cfg_attr(
1508+
not(bootstrap),
1509+
rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0"),
1510+
)]
15041511
#[inline]
15051512
pub const fn new(value: T) -> UnsafeCell<T> {
15061513
UnsafeCell { value }
@@ -1543,6 +1550,10 @@ impl<T: ?Sized> UnsafeCell<T> {
15431550
/// ```
15441551
#[inline]
15451552
#[stable(feature = "rust1", since = "1.0.0")]
1553+
#[cfg_attr(
1554+
not(bootstrap),
1555+
rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0"),
1556+
)]
15461557
pub const fn get(&self) -> *mut T {
15471558
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
15481559
// #[repr(transparent)]. This exploits libstd's special status, there is

src/libcore/char/methods.rs

+4
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ impl char {
911911
/// assert!(!non_ascii.is_ascii());
912912
/// ```
913913
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
914+
#[cfg_attr(
915+
not(bootstrap),
916+
rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.32.0"),
917+
)]
914918
#[inline]
915919
pub const fn is_ascii(&self) -> bool {
916920
*self as u32 <= 0x7F

src/libcore/convert/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub use num::FloatToInt;
9999
/// assert_eq!(vec![1, 3], filtered);
100100
/// ```
101101
#[stable(feature = "convert_id", since = "1.33.0")]
102+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_identity", since = "1.33.0"))]
102103
#[inline]
103104
pub const fn identity<T>(x: T) -> T {
104105
x

src/libcore/intrinsics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,11 @@ extern "rust-intrinsic" {
939939
/// }
940940
/// ```
941941
#[stable(feature = "rust1", since = "1.0.0")]
942-
#[rustc_const_unstable(feature = "const_transmute")]
942+
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_transmute"))]
943+
#[cfg_attr(
944+
not(bootstrap),
945+
rustc_const_unstable(feature = "const_transmute", issue = "53605"),
946+
)]
943947
pub fn transmute<T, U>(e: T) -> U;
944948

945949
/// Returns `true` if the actual type given as `T` requires drop

src/libcore/iter/sources.rs

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ impl<T> Default for Empty<T> {
281281
/// assert_eq!(None, nope.next());
282282
/// ```
283283
#[stable(feature = "iter_empty", since = "1.2.0")]
284+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_iter_empty", since = "1.32.0"))]
284285
pub const fn empty<T>() -> Empty<T> {
285286
Empty(marker::PhantomData)
286287
}

src/libcore/mem/manually_drop.rs

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ impl<T> ManuallyDrop<T> {
6363
/// ManuallyDrop::new(Box::new(()));
6464
/// ```
6565
#[stable(feature = "manually_drop", since = "1.20.0")]
66+
#[cfg_attr(
67+
not(bootstrap),
68+
rustc_const_stable(feature = "const_manually_drop", since = "1.36.0"),
69+
)]
6670
#[inline(always)]
6771
pub const fn new(value: T) -> ManuallyDrop<T> {
6872
ManuallyDrop { value }
@@ -80,6 +84,10 @@ impl<T> ManuallyDrop<T> {
8084
/// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`.
8185
/// ```
8286
#[stable(feature = "manually_drop", since = "1.20.0")]
87+
#[cfg_attr(
88+
not(bootstrap),
89+
rustc_const_stable(feature = "const_manually_drop", since = "1.36.0"),
90+
)]
8391
#[inline(always)]
8492
pub const fn into_inner(slot: ManuallyDrop<T>) -> T {
8593
slot.value

src/libcore/mem/maybe_uninit.rs

+8
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ impl<T> MaybeUninit<T> {
250250
///
251251
/// [`assume_init`]: #method.assume_init
252252
#[stable(feature = "maybe_uninit", since = "1.36.0")]
253+
#[cfg_attr(
254+
not(bootstrap),
255+
rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0"),
256+
)]
253257
#[inline(always)]
254258
pub const fn new(val: T) -> MaybeUninit<T> {
255259
MaybeUninit { value: ManuallyDrop::new(val) }
@@ -264,6 +268,10 @@ impl<T> MaybeUninit<T> {
264268
///
265269
/// [type]: union.MaybeUninit.html
266270
#[stable(feature = "maybe_uninit", since = "1.36.0")]
271+
#[cfg_attr(
272+
not(bootstrap),
273+
rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0"),
274+
)]
267275
#[inline(always)]
268276
#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_uninit")]
269277
pub const fn uninit() -> MaybeUninit<T> {

src/libcore/mem/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
271271
#[inline(always)]
272272
#[stable(feature = "rust1", since = "1.0.0")]
273273
#[rustc_promotable]
274+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_size_of", since = "1.32.0"))]
274275
pub const fn size_of<T>() -> usize {
275276
intrinsics::size_of::<T>()
276277
}
@@ -371,6 +372,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
371372
#[inline(always)]
372373
#[stable(feature = "rust1", since = "1.0.0")]
373374
#[rustc_promotable]
375+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_align_of", since = "1.32.0"))]
374376
pub const fn align_of<T>() -> usize {
375377
intrinsics::min_align_of::<T>()
376378
}
@@ -453,6 +455,7 @@ pub fn align_of_val<T: ?Sized>(val: &T) -> usize {
453455
/// ```
454456
#[inline]
455457
#[stable(feature = "needs_drop", since = "1.21.0")]
458+
#[cfg_attr(not(bootstrap), rustc_const_stable(feature = "const_needs_drop", since = "1.36.0"))]
456459
pub const fn needs_drop<T>() -> bool {
457460
intrinsics::needs_drop::<T>()
458461
}

0 commit comments

Comments
 (0)