Skip to content

Commit d066dfd

Browse files
committed
we can now enable the 'const stable fn must be stable' check
1 parent f370f34 commit d066dfd

File tree

9 files changed

+27
-13
lines changed

9 files changed

+27
-13
lines changed

compiler/rustc_error_codes/src/error_codes/E0539.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const fn unstable_fn() {}
4545
#[stable(feature = "stable_struct", since = "1.39.0")] // ok!
4646
struct Stable;
4747
48+
#[stable(feature = "stable_fn", since = "1.39.0")]
4849
#[rustc_const_stable(feature = "stable_fn", since = "1.39.0")] // ok!
4950
const fn stable_fn() {}
5051
```

compiler/rustc_error_codes/src/error_codes/E0542.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ To fix this issue, you need to provide the `since` field. Example:
3030
#[stable(feature = "_stable_fn", since = "1.0.0")] // ok!
3131
fn _stable_fn() {}
3232
33+
#[stable(feature = "_stable_const_fn", since = "1.0.0")]
3334
#[rustc_const_stable(feature = "_stable_const_fn", since = "1.0.0")] // ok!
3435
const fn _stable_const_fn() {}
3536

compiler/rustc_passes/src/stability.rs

-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
189189
&& let Some(fn_sig) = fn_sig
190190
&& const_stab.is_const_stable()
191191
&& !stab.is_some_and(|(s, _)| s.is_stable())
192-
// FIXME: we skip this check targets until
193-
// <https://github.com/rust-lang/stdarch/pull/1654> propagates.
194-
&& false
195192
{
196193
self.tcx
197194
.dcx()

library/std/src/sys/sync/condvar/no_threads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub struct Condvar {}
55

66
impl Condvar {
77
#[inline]
8-
#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
8+
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_locks", since = "1.63.0"))]
99
pub const fn new() -> Condvar {
1010
Condvar {}
1111
}

library/std/src/sys/sync/mutex/no_threads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ unsafe impl Sync for Mutex {} // no threads on this platform
1010

1111
impl Mutex {
1212
#[inline]
13-
#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
13+
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_locks", since = "1.63.0"))]
1414
pub const fn new() -> Mutex {
1515
Mutex { locked: Cell::new(false) }
1616
}

library/std/src/sys/sync/once/no_threads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ unsafe impl Sync for Once {}
3535

3636
impl Once {
3737
#[inline]
38-
#[rustc_const_stable(feature = "const_once_new", since = "1.32.0")]
38+
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_once_new", since = "1.32.0"))]
3939
pub const fn new() -> Once {
4040
Once { state: Cell::new(State::Incomplete) }
4141
}

library/std/src/sys/sync/rwlock/no_threads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ unsafe impl Sync for RwLock {} // no threads on this platform
1010

1111
impl RwLock {
1212
#[inline]
13-
#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
13+
#[cfg_attr(bootstrap, rustc_const_stable(feature = "const_locks", since = "1.63.0"))]
1414
pub const fn new() -> RwLock {
1515
RwLock { mode: Cell::new(0) }
1616
}

tests/ui/consts/rustc-const-stability-require-const.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ pub const fn foobar() {}
4747
pub const fn barfoo() {}
4848

4949
// `rustc_const_stable` also requires the function to be stable.
50-
// FIXME: these are disabled until <https://github.com/rust-lang/stdarch/pull/1654> propagates.
5150

5251
#[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
5352
const fn barfoo_unmarked() {}
54-
// FIXME disabled ERROR can only be applied to functions that are declared `#[stable]`
53+
//~^ ERROR can only be applied to functions that are declared `#[stable]`
5554

5655
#[unstable(feature = "unstable", issue = "none")]
5756
#[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
5857
pub const fn barfoo_unstable() {}
59-
// FIXME disabled ERROR can only be applied to functions that are declared `#[stable]`
58+
//~^ ERROR can only be applied to functions that are declared `#[stable]`
6059

6160
// `#[rustc_const_stable_indirect]` also requires a const fn
6261
#[rustc_const_stable_indirect]

tests/ui/consts/rustc-const-stability-require-const.stderr

+19-3
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,33 @@ help: make the function or method const
7070
LL | pub extern "C" fn foo_c() {}
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7272

73+
error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
74+
--> $DIR/rustc-const-stability-require-const.rs:52:1
75+
|
76+
LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
77+
| ---------------------------------------------------------------- attribute specified here
78+
LL | const fn barfoo_unmarked() {}
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
81+
error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
82+
--> $DIR/rustc-const-stability-require-const.rs:57:1
83+
|
84+
LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
85+
| ---------------------------------------------------------------- attribute specified here
86+
LL | pub const fn barfoo_unstable() {}
87+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
7389
error: attributes `#[rustc_const_unstable]`, `#[rustc_const_stable]` and `#[rustc_const_stable_indirect]` require the function or method to be `const`
74-
--> $DIR/rustc-const-stability-require-const.rs:64:1
90+
--> $DIR/rustc-const-stability-require-const.rs:63:1
7591
|
7692
LL | pub fn not_a_const_fn() {}
7793
| ^^^^^^^^^^^^^^^^^^^^^^^
7894
|
7995
help: make the function or method const
80-
--> $DIR/rustc-const-stability-require-const.rs:64:1
96+
--> $DIR/rustc-const-stability-require-const.rs:63:1
8197
|
8298
LL | pub fn not_a_const_fn() {}
8399
| ^^^^^^^^^^^^^^^^^^^^^^^
84100

85-
error: aborting due to 7 previous errors
101+
error: aborting due to 9 previous errors
86102

0 commit comments

Comments
 (0)