Skip to content

Commit 22627be

Browse files
committed
Require opt-in for promoting const fn calls
1 parent a1aae29 commit 22627be

Some content is hidden

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

54 files changed

+204
-30
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#![feature(optin_builtin_traits)]
104104
#![feature(pattern)]
105105
#![feature(pin)]
106+
#![feature(promotable_const_fn)]
106107
#![feature(ptr_internals)]
107108
#![feature(ptr_offset_from)]
108109
#![feature(repr_transparent)]

src/liballoc/raw_vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct RawVec<T, A: Alloc = Global> {
5656
impl<T, A: Alloc> RawVec<T, A> {
5757
/// Like `new` but parameterized over the choice of allocator for
5858
/// the returned RawVec.
59+
#[promotable_const_fn]
5960
pub const fn new_in(a: A) -> Self {
6061
// !0 is usize::MAX. This branch should be stripped at compile time.
6162
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`
@@ -123,6 +124,7 @@ impl<T> RawVec<T, Global> {
123124
/// RawVec with capacity 0. If T has 0 size, then it makes a
124125
/// RawVec with capacity `usize::MAX`. Useful for implementing
125126
/// delayed allocation.
127+
#[promotable_const_fn]
126128
pub const fn new() -> Self {
127129
Self::new_in(Global)
128130
}

src/liballoc/string.rs

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl String {
381381
#[inline]
382382
#[stable(feature = "rust1", since = "1.0.0")]
383383
#[rustc_const_unstable(feature = "const_string_new")]
384+
#[promotable_const_fn]
384385
pub const fn new() -> String {
385386
String { vec: Vec::new() }
386387
}

src/liballoc/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ impl<T> Vec<T> {
320320
#[inline]
321321
#[stable(feature = "rust1", since = "1.0.0")]
322322
#[rustc_const_unstable(feature = "const_vec_new")]
323+
#[promotable_const_fn]
323324
pub const fn new() -> Vec<T> {
324325
Vec {
325326
buf: RawVec::new(),

src/libcore/any.rs

+1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ impl TypeId {
458458
/// ```
459459
#[stable(feature = "rust1", since = "1.0.0")]
460460
#[rustc_const_unstable(feature="const_type_id")]
461+
#[promotable_const_fn]
461462
pub const fn of<T: ?Sized + 'static>() -> TypeId {
462463
TypeId {
463464
t: unsafe { intrinsics::type_id::<T>() },

src/libcore/cell.rs

+3
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ impl<T> Cell<T> {
374374
/// ```
375375
#[stable(feature = "rust1", since = "1.0.0")]
376376
#[inline]
377+
#[promotable_const_fn]
377378
pub const fn new(value: T) -> Cell<T> {
378379
Cell {
379380
value: UnsafeCell::new(value),
@@ -588,6 +589,7 @@ impl<T> RefCell<T> {
588589
/// ```
589590
#[stable(feature = "rust1", since = "1.0.0")]
590591
#[inline]
592+
#[promotable_const_fn]
591593
pub const fn new(value: T) -> RefCell<T> {
592594
RefCell {
593595
value: UnsafeCell::new(value),
@@ -1304,6 +1306,7 @@ impl<T> UnsafeCell<T> {
13041306
/// ```
13051307
#[stable(feature = "rust1", since = "1.0.0")]
13061308
#[inline]
1309+
#[promotable_const_fn]
13071310
pub const fn new(value: T) -> UnsafeCell<T> {
13081311
UnsafeCell { value: value }
13091312
}

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#![feature(on_unimplemented)]
100100
#![feature(optin_builtin_traits)]
101101
#![feature(prelude_import)]
102+
#![feature(promotable_const_fn)]
102103
#![feature(repr_simd, platform_intrinsics)]
103104
#![feature(repr_transparent)]
104105
#![feature(rustc_attrs)]

src/libcore/mem.rs

+3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ pub fn forget<T>(t: T) {
314314
/// [alignment]: ./fn.align_of.html
315315
#[inline]
316316
#[stable(feature = "rust1", since = "1.0.0")]
317+
#[promotable_const_fn]
317318
pub const fn size_of<T>() -> usize {
318319
unsafe { intrinsics::size_of::<T>() }
319320
}
@@ -405,6 +406,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
405406
/// ```
406407
#[inline]
407408
#[stable(feature = "rust1", since = "1.0.0")]
409+
#[promotable_const_fn]
408410
pub const fn align_of<T>() -> usize {
409411
unsafe { intrinsics::min_align_of::<T>() }
410412
}
@@ -966,6 +968,7 @@ impl<T> ManuallyDrop<T> {
966968
#[stable(feature = "manually_drop", since = "1.20.0")]
967969
#[rustc_const_unstable(feature = "const_manually_drop_new")]
968970
#[inline]
971+
#[promotable_const_fn]
969972
pub const fn new(value: T) -> ManuallyDrop<T> {
970973
ManuallyDrop { value: value }
971974
}

src/libcore/num/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ $EndFeature, "
200200
```"),
201201
#[stable(feature = "rust1", since = "1.0.0")]
202202
#[inline]
203+
#[promotable_const_fn]
203204
pub const fn min_value() -> Self {
204205
!0 ^ ((!0 as $UnsignedT) >> 1) as Self
205206
}
@@ -218,6 +219,7 @@ $EndFeature, "
218219
```"),
219220
#[stable(feature = "rust1", since = "1.0.0")]
220221
#[inline]
222+
#[promotable_const_fn]
221223
pub const fn max_value() -> Self {
222224
!Self::min_value()
223225
}
@@ -2103,6 +2105,7 @@ Basic usage:
21032105
```"),
21042106
#[stable(feature = "rust1", since = "1.0.0")]
21052107
#[inline]
2108+
#[promotable_const_fn]
21062109
pub const fn min_value() -> Self { 0 }
21072110
}
21082111

@@ -2119,6 +2122,7 @@ stringify!($MaxV), ");", $EndFeature, "
21192122
```"),
21202123
#[stable(feature = "rust1", since = "1.0.0")]
21212124
#[inline]
2125+
#[promotable_const_fn]
21222126
pub const fn max_value() -> Self { !0 }
21232127
}
21242128

src/libcore/num/wrapping.rs

+2
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ assert_eq!(<Wrapping<", stringify!($t), ">>::min_value(), ",
344344
```"),
345345
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
346346
#[inline]
347+
#[promotable_const_fn]
347348
pub const fn min_value() -> Self {
348349
Wrapping(<$t>::min_value())
349350
}
@@ -365,6 +366,7 @@ assert_eq!(<Wrapping<", stringify!($t), ">>::max_value(), ",
365366
```"),
366367
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
367368
#[inline]
369+
#[promotable_const_fn]
368370
pub const fn max_value() -> Self {
369371
Wrapping(<$t>::max_value())
370372
}

src/libcore/ops/range.rs

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ impl<Idx> RangeInclusive<Idx> {
349349
/// ```
350350
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
351351
#[inline]
352+
#[promotable_const_fn]
352353
pub const fn new(start: Idx, end: Idx) -> Self {
353354
Self { start, end }
354355
}

src/libcore/ptr.rs

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
7474
/// ```
7575
#[inline]
7676
#[stable(feature = "rust1", since = "1.0.0")]
77+
#[promotable_const_fn]
7778
pub const fn null<T>() -> *const T { 0 as *const T }
7879

7980
/// Creates a null mutable raw pointer.
@@ -88,6 +89,7 @@ pub const fn null<T>() -> *const T { 0 as *const T }
8889
/// ```
8990
#[inline]
9091
#[stable(feature = "rust1", since = "1.0.0")]
92+
#[promotable_const_fn]
9193
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
9294

9395
/// Swaps the values at two mutable locations of the same type, without
@@ -2730,6 +2732,7 @@ impl<T: Sized> Unique<T> {
27302732
/// This is useful for initializing types which lazily allocate, like
27312733
/// `Vec::new` does.
27322734
// FIXME: rename to dangling() to match NonNull?
2735+
#[promotable_const_fn]
27332736
pub const fn empty() -> Self {
27342737
unsafe {
27352738
Unique::new_unchecked(mem::align_of::<T>() as *mut T)
@@ -2744,6 +2747,7 @@ impl<T: ?Sized> Unique<T> {
27442747
/// # Safety
27452748
///
27462749
/// `ptr` must be non-null.
2750+
#[promotable_const_fn]
27472751
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
27482752
Unique { pointer: NonZero(ptr as _), _marker: PhantomData }
27492753
}

src/libcore/sync/atomic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl AtomicBool {
246246
/// ```
247247
#[inline]
248248
#[stable(feature = "rust1", since = "1.0.0")]
249+
#[promotable_const_fn]
249250
pub const fn new(v: bool) -> AtomicBool {
250251
AtomicBool { v: UnsafeCell::new(v as u8) }
251252
}
@@ -659,6 +660,7 @@ impl<T> AtomicPtr<T> {
659660
/// ```
660661
#[inline]
661662
#[stable(feature = "rust1", since = "1.0.0")]
663+
#[promotable_const_fn]
662664
pub const fn new(p: *mut T) -> AtomicPtr<T> {
663665
AtomicPtr { p: UnsafeCell::new(p) }
664666
}
@@ -1011,6 +1013,7 @@ let atomic_forty_two = ", stringify!($atomic_type), "::new(42);
10111013
```"),
10121014
#[inline]
10131015
#[$stable]
1016+
#[promotable_const_fn]
10141017
pub const fn new(v: $int_type) -> Self {
10151018
$atomic_type {v: UnsafeCell::new(v)}
10161019
}

src/libcore/time.rs

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl Duration {
108108
/// ```
109109
#[stable(feature = "duration", since = "1.3.0")]
110110
#[inline]
111+
#[promotable_const_fn]
111112
pub const fn from_secs(secs: u64) -> Duration {
112113
Duration { secs: secs, nanos: 0 }
113114
}
@@ -126,6 +127,7 @@ impl Duration {
126127
/// ```
127128
#[stable(feature = "duration", since = "1.3.0")]
128129
#[inline]
130+
#[promotable_const_fn]
129131
pub const fn from_millis(millis: u64) -> Duration {
130132
Duration {
131133
secs: millis / MILLIS_PER_SEC,
@@ -147,6 +149,7 @@ impl Duration {
147149
/// ```
148150
#[stable(feature = "duration_from_micros", since = "1.27.0")]
149151
#[inline]
152+
#[promotable_const_fn]
150153
pub const fn from_micros(micros: u64) -> Duration {
151154
Duration {
152155
secs: micros / MICROS_PER_SEC,
@@ -168,6 +171,7 @@ impl Duration {
168171
/// ```
169172
#[stable(feature = "duration_extras", since = "1.27.0")]
170173
#[inline]
174+
#[promotable_const_fn]
171175
pub const fn from_nanos(nanos: u64) -> Duration {
172176
Duration {
173177
secs: nanos / (NANOS_PER_SEC as u64),

0 commit comments

Comments
 (0)