mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
we can now enable the 'const stable fn must be stable' check
This commit is contained in:
parent
f370f3493d
commit
d066dfdb83
@ -45,6 +45,7 @@ const fn unstable_fn() {}
|
||||
#[stable(feature = "stable_struct", since = "1.39.0")] // ok!
|
||||
struct Stable;
|
||||
|
||||
#[stable(feature = "stable_fn", since = "1.39.0")]
|
||||
#[rustc_const_stable(feature = "stable_fn", since = "1.39.0")] // ok!
|
||||
const fn stable_fn() {}
|
||||
```
|
||||
|
@ -30,6 +30,7 @@ To fix this issue, you need to provide the `since` field. Example:
|
||||
#[stable(feature = "_stable_fn", since = "1.0.0")] // ok!
|
||||
fn _stable_fn() {}
|
||||
|
||||
#[stable(feature = "_stable_const_fn", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "_stable_const_fn", since = "1.0.0")] // ok!
|
||||
const fn _stable_const_fn() {}
|
||||
|
||||
|
@ -189,9 +189,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||
&& let Some(fn_sig) = fn_sig
|
||||
&& const_stab.is_const_stable()
|
||||
&& !stab.is_some_and(|(s, _)| s.is_stable())
|
||||
// FIXME: we skip this check targets until
|
||||
// <https://github.com/rust-lang/stdarch/pull/1654> propagates.
|
||||
&& false
|
||||
{
|
||||
self.tcx
|
||||
.dcx()
|
||||
|
@ -5,7 +5,7 @@ pub struct Condvar {}
|
||||
|
||||
impl Condvar {
|
||||
#[inline]
|
||||
#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
|
||||
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_locks", since = "1.63.0"))]
|
||||
pub const fn new() -> Condvar {
|
||||
Condvar {}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ unsafe impl Sync for Mutex {} // no threads on this platform
|
||||
|
||||
impl Mutex {
|
||||
#[inline]
|
||||
#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
|
||||
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_locks", since = "1.63.0"))]
|
||||
pub const fn new() -> Mutex {
|
||||
Mutex { locked: Cell::new(false) }
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ unsafe impl Sync for Once {}
|
||||
|
||||
impl Once {
|
||||
#[inline]
|
||||
#[rustc_const_stable(feature = "const_once_new", since = "1.32.0")]
|
||||
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_once_new", since = "1.32.0"))]
|
||||
pub const fn new() -> Once {
|
||||
Once { state: Cell::new(State::Incomplete) }
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ unsafe impl Sync for RwLock {} // no threads on this platform
|
||||
|
||||
impl RwLock {
|
||||
#[inline]
|
||||
#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
|
||||
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_locks", since = "1.63.0"))]
|
||||
pub const fn new() -> RwLock {
|
||||
RwLock { mode: Cell::new(0) }
|
||||
}
|
||||
|
@ -47,16 +47,15 @@ pub const fn foobar() {}
|
||||
pub const fn barfoo() {}
|
||||
|
||||
// `rustc_const_stable` also requires the function to be stable.
|
||||
// FIXME: these are disabled until <https://github.com/rust-lang/stdarch/pull/1654> propagates.
|
||||
|
||||
#[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
|
||||
const fn barfoo_unmarked() {}
|
||||
// FIXME disabled ERROR can only be applied to functions that are declared `#[stable]`
|
||||
//~^ ERROR can only be applied to functions that are declared `#[stable]`
|
||||
|
||||
#[unstable(feature = "unstable", issue = "none")]
|
||||
#[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
|
||||
pub const fn barfoo_unstable() {}
|
||||
// FIXME disabled ERROR can only be applied to functions that are declared `#[stable]`
|
||||
//~^ ERROR can only be applied to functions that are declared `#[stable]`
|
||||
|
||||
// `#[rustc_const_stable_indirect]` also requires a const fn
|
||||
#[rustc_const_stable_indirect]
|
||||
|
@ -70,17 +70,33 @@ help: make the function or method const
|
||||
LL | pub extern "C" fn foo_c() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
|
||||
--> $DIR/rustc-const-stability-require-const.rs:52:1
|
||||
|
|
||||
LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
|
||||
| ---------------------------------------------------------------- attribute specified here
|
||||
LL | const fn barfoo_unmarked() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
|
||||
--> $DIR/rustc-const-stability-require-const.rs:57:1
|
||||
|
|
||||
LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
|
||||
| ---------------------------------------------------------------- attribute specified here
|
||||
LL | pub const fn barfoo_unstable() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: attributes `#[rustc_const_unstable]`, `#[rustc_const_stable]` and `#[rustc_const_stable_indirect]` require the function or method to be `const`
|
||||
--> $DIR/rustc-const-stability-require-const.rs:64:1
|
||||
--> $DIR/rustc-const-stability-require-const.rs:63:1
|
||||
|
|
||||
LL | pub fn not_a_const_fn() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function or method const
|
||||
--> $DIR/rustc-const-stability-require-const.rs:64:1
|
||||
--> $DIR/rustc-const-stability-require-const.rs:63:1
|
||||
|
|
||||
LL | pub fn not_a_const_fn() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user