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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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
}

0 commit comments

Comments
 (0)