Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require stable/unstable annotations for the constness of all stable fns with a const modifier #67136

Merged
merged 9 commits into from
Dec 14, 2019
4 changes: 4 additions & 0 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ impl<T> LinkedList<T> {
/// let list: LinkedList<u32> = 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 {
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
#![feature(unsized_locals)]
#![feature(allocator_internals)]
#![cfg_attr(bootstrap, feature(on_unimplemented))]
#![feature(rustc_const_unstable)]
#![cfg_attr(bootstrap, feature(rustc_const_unstable))]
#![feature(slice_partition_dedup)]
#![feature(maybe_uninit_extra, maybe_uninit_slice)]
#![feature(alloc_layout_extra)]
Expand Down
4 changes: 4 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
4 changes: 4 additions & 0 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ impl<T> Vec<T> {
/// let mut vec: Vec<i32> = 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<T> {
Vec {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Layout {
/// This function is unsafe as it does not verify the preconditions from
/// [`Layout::from_size_align`](#method.from_size_align).
#[stable(feature = "alloc_layout", since = "1.28.0")]
#[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) }
Expand Down
9 changes: 6 additions & 3 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ?Sized + 'static>() -> TypeId {
TypeId {
#[cfg(bootstrap)]
Expand Down Expand Up @@ -461,7 +462,8 @@ impl 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<T: ?Sized>() -> &'static str {
intrinsics::type_name::<T>()
}
Expand Down Expand Up @@ -499,7 +501,8 @@ pub const fn type_name<T: ?Sized>() -> &'static str {
/// println!("{}", type_name_of_val(&y));
/// ```
#[unstable(feature = "type_name_of_val", issue = "66359")]
#[rustc_const_unstable(feature = "const_type_name")]
#[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<T: ?Sized>(val: &T) -> &'static str {
let _ = val;
type_name::<T>()
Expand Down
11 changes: 11 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ impl<T> Cell<T> {
/// 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<T> {
Cell {
Expand Down Expand Up @@ -469,6 +470,7 @@ impl<T: ?Sized> Cell<T> {
/// ```
#[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()
}
Expand Down Expand Up @@ -649,6 +651,7 @@ impl<T> RefCell<T> {
/// 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<T> {
RefCell {
Expand Down Expand Up @@ -1501,6 +1504,10 @@ impl<T> UnsafeCell<T> {
/// 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<T> {
UnsafeCell { value }
Expand Down Expand Up @@ -1543,6 +1550,10 @@ impl<T: ?Sized> UnsafeCell<T> {
/// ```
#[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<T>` to `T` because of
// #[repr(transparent)]. This exploits libstd's special status, there is
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ impl char {
/// 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
Expand Down
1 change: 1 addition & 0 deletions src/libcore/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub use num::FloatToInt;
/// 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<T>(x: T) -> T {
x
Expand Down
6 changes: 5 additions & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,11 @@ extern "rust-intrinsic" {
/// }
/// ```
#[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<T, U>(e: T) -> U;

/// Returns `true` if the actual type given as `T` requires drop
Expand Down
1 change: 1 addition & 0 deletions src/libcore/iter/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ impl<T> Default for Empty<T> {
/// 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<T>() -> Empty<T> {
Empty(marker::PhantomData)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
#![feature(prelude_import)]
#![feature(repr_simd, platform_intrinsics)]
#![feature(rustc_attrs)]
#![feature(rustc_const_unstable)]
#![cfg_attr(bootstrap, feature(rustc_const_unstable))]
#![feature(simd_ffi)]
#![feature(specialization)]
#![feature(staged_api)]
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/mem/manually_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl<T> ManuallyDrop<T> {
/// 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<T> {
ManuallyDrop { value }
Expand All @@ -80,6 +84,10 @@ impl<T> ManuallyDrop<T> {
/// 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>) -> T {
slot.value
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ impl<T> MaybeUninit<T> {
///
/// [`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<T> {
MaybeUninit { value: ManuallyDrop::new(val) }
Expand All @@ -264,6 +268,10 @@ impl<T> MaybeUninit<T> {
///
/// [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<T> {
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ pub fn forget_unsized<T: ?Sized>(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<T>() -> usize {
intrinsics::size_of::<T>()
}
Expand Down Expand Up @@ -371,6 +372,7 @@ pub fn min_align_of_val<T: ?Sized>(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<T>() -> usize {
intrinsics::min_align_of::<T>()
}
Expand Down Expand Up @@ -453,6 +455,7 @@ pub fn align_of_val<T: ?Sized>(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<T>() -> bool {
intrinsics::needs_drop::<T>()
}
Expand Down
Loading