From f370f3493d3c85c7032a98e6c22b419251f18d2a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 28 Oct 2024 09:42:42 +0100 Subject: [PATCH 1/2] bump stdarch --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index c881fe3231b..ff9a4445038 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit c881fe3231b3947a4766aa15a26a93022fbb8723 +Subproject commit ff9a4445038eae46fd095188740946808581bc0e From d066dfdb835f15fe2c4d2bdb31d88cb948b360ad Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 26 Oct 2024 09:40:03 +0200 Subject: [PATCH 2/2] we can now enable the 'const stable fn must be stable' check --- .../src/error_codes/E0539.md | 1 + .../src/error_codes/E0542.md | 1 + compiler/rustc_passes/src/stability.rs | 3 --- .../std/src/sys/sync/condvar/no_threads.rs | 2 +- library/std/src/sys/sync/mutex/no_threads.rs | 2 +- library/std/src/sys/sync/once/no_threads.rs | 2 +- library/std/src/sys/sync/rwlock/no_threads.rs | 2 +- .../rustc-const-stability-require-const.rs | 5 ++--- ...rustc-const-stability-require-const.stderr | 22 ++++++++++++++++--- 9 files changed, 27 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0539.md b/compiler/rustc_error_codes/src/error_codes/E0539.md index cd28afbc48d..6b2e23ba2d8 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0539.md +++ b/compiler/rustc_error_codes/src/error_codes/E0539.md @@ -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() {} ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0542.md b/compiler/rustc_error_codes/src/error_codes/E0542.md index be186dbd2cc..70590f2e48e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0542.md +++ b/compiler/rustc_error_codes/src/error_codes/E0542.md @@ -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() {} diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 67e7496771d..e815615fb72 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -189,9 +189,6 @@ fn annotate( && 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 - // propagates. - && false { self.tcx .dcx() diff --git a/library/std/src/sys/sync/condvar/no_threads.rs b/library/std/src/sys/sync/condvar/no_threads.rs index 36b89c5f5be..2a67ed766aa 100644 --- a/library/std/src/sys/sync/condvar/no_threads.rs +++ b/library/std/src/sys/sync/condvar/no_threads.rs @@ -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 {} } diff --git a/library/std/src/sys/sync/mutex/no_threads.rs b/library/std/src/sys/sync/mutex/no_threads.rs index 4a13c55fb8b..7b243575e01 100644 --- a/library/std/src/sys/sync/mutex/no_threads.rs +++ b/library/std/src/sys/sync/mutex/no_threads.rs @@ -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) } } diff --git a/library/std/src/sys/sync/once/no_threads.rs b/library/std/src/sys/sync/once/no_threads.rs index cdcffe790f5..fb1b496510a 100644 --- a/library/std/src/sys/sync/once/no_threads.rs +++ b/library/std/src/sys/sync/once/no_threads.rs @@ -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) } } diff --git a/library/std/src/sys/sync/rwlock/no_threads.rs b/library/std/src/sys/sync/rwlock/no_threads.rs index 789ef9b29e5..6965e2e2cab 100644 --- a/library/std/src/sys/sync/rwlock/no_threads.rs +++ b/library/std/src/sys/sync/rwlock/no_threads.rs @@ -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) } } diff --git a/tests/ui/consts/rustc-const-stability-require-const.rs b/tests/ui/consts/rustc-const-stability-require-const.rs index 1c66f6e2aa5..6cc3f0f0da1 100644 --- a/tests/ui/consts/rustc-const-stability-require-const.rs +++ b/tests/ui/consts/rustc-const-stability-require-const.rs @@ -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 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] diff --git a/tests/ui/consts/rustc-const-stability-require-const.stderr b/tests/ui/consts/rustc-const-stability-require-const.stderr index 09b96ce6f83..d9a7d37cbcd 100644 --- a/tests/ui/consts/rustc-const-stability-require-const.stderr +++ b/tests/ui/consts/rustc-const-stability-require-const.stderr @@ -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