Auto merge of #67136 - oli-obk:const_stability, r=Centril

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

r? @RalfJung @Centril

Every `#[stable]` const fn now needs either a `#[rustc_const_unstable]` attribute or a `#[rustc_const_stable]` attribute. You can't silently stabilize the constness of a function anymore.
This commit is contained in:
bors 2019-12-14 10:21:32 +00:00
commit c8ea4ace92
66 changed files with 717 additions and 181 deletions

View file

@ -4,12 +4,12 @@
reason = "who ever let humans program computers, we're apparently really bad at it",
issue = "0")]
#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(foo, foo2)]
#![feature(staged_api)]
// @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32'
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo")]
#[rustc_const_unstable(feature="foo", issue = "0")]
pub const unsafe fn foo() -> u32 { 42 }
// @has 'foo/fn.foo2.html' '//pre' 'pub fn foo2() -> u32'
@ -18,6 +18,7 @@ pub const fn foo2() -> u32 { 42 }
// @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32'
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
pub const fn bar2() -> u32 { 42 }
// @has 'foo/fn.foo2_gated.html' '//pre' 'pub unsafe fn foo2_gated() -> u32'
@ -26,6 +27,7 @@ pub const unsafe fn foo2_gated() -> u32 { 42 }
// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const unsafe fn bar2_gated() -> u32'
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
pub const unsafe fn bar2_gated() -> u32 { 42 }
// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub unsafe fn bar_not_gated() -> u32'

View file

@ -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 struct Foo(usize);
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 }

View file

@ -3,9 +3,9 @@
#![crate_type="rlib"]
#![stable(feature = "rust1", since = "1.0.0")]
#![feature(rustc_const_unstable, const_fn)]
#![feature(const_fn)]
#![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 }

View file

@ -3,11 +3,11 @@
we're apparently really bad at it",
issue = "0")]
#![feature(rustc_const_unstable, const_fn)]
#![feature(const_fn)]
#![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 }

View file

@ -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() {}

View file

@ -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()) {}
| ^

View file

@ -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() = || ();

View file

@ -3,14 +3,15 @@
we're apparently really bad at it",
issue = "0")]
#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(const_fn, foo, foo2)]
#![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`

View file

@ -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() }
| ^^^^^^^^^^^^

View file

@ -3,14 +3,15 @@
we're apparently really bad at it",
issue = "0")]
#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(const_fn, foo, foo2)]
#![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 bar() -> u32 { unsafe { foo() } } //~ ERROR can only call other
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 bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool
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`

View file

@ -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() } }
| ^^^^^^^^^^^^

View file

@ -3,14 +3,15 @@
we're apparently really bad at it",
issue = "0")]
#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(const_fn, foo, foo2)]
#![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 unsafe 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 unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `const fn`
@ -26,6 +28,7 @@ const unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `const fn
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`

View file

@ -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() }
| ^^^^^^^^^^^^

View file

@ -14,7 +14,7 @@ enum Opt<T> {
}
impl<T> Opt<T> {
#[rustc_const_unstable(feature = "foo")]
#[rustc_const_unstable(feature = "foo", issue = "0")]
#[stable(feature = "rust1", since = "1.0.0")]
const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
//~^ ERROR destructors cannot be evaluated at compile-time

View file

@ -1,8 +1,6 @@
// compile-flags: -Z allow_features=
// Note: This test uses rustc internal flags because they will never stabilize.
#![feature(rustc_const_unstable)] //~ ERROR
#![feature(lang_items)] //~ ERROR
#![feature(unknown_stdlib_feature)] //~ ERROR

View file

@ -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`.

View file

@ -1,8 +1,6 @@
// compile-flags: -Z allow_features=lang_items
// Note: This test uses rustc internal flags because they will never stabilize.
#![feature(rustc_const_unstable)] //~ ERROR
#![feature(lang_items)]
#![feature(unknown_stdlib_feature)] //~ ERROR

View file

@ -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`.

View file

@ -1,11 +1,8 @@
// Test internal const fn feature gate.
#![feature(staged_api)]
#![feature(const_fn)]
//#![feature(rustc_const_unstable)]
#[stable(feature="zing", since="1.0.0")]
#[rustc_const_unstable(feature="fzzzzzt")] //~ERROR internal feature
#[rustc_const_unstable(feature="fzzzzzt")] //~ stability attributes may not be used outside
pub const fn bazinga() {}
fn main() {

View file

@ -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`.

View file

@ -22,6 +22,7 @@ use std::process::{Command, Stdio};
// 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 }

View file

@ -1,6 +1,6 @@
// Various checks that stability attributes are used correctly, per RFC 507
#![feature(const_fn, staged_api, rustc_const_unstable)]
#![feature(const_fn, staged_api)]
#![stable(feature = "rust1", since = "1.0.0")]
@ -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() { }

View file

@ -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() { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^