about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-08-31 20:36:27 +0200
committerGitHub <noreply@github.com>2024-08-31 20:36:27 +0200
commitb8b2a6503555fc5ea3b7c6516216c95e7b1a19ed (patch)
treeb71f070c7622583d35c6bff2da7cecbc32883282
parent08b813b30e02718dda6cdc3ca0dabe0d6a113e2b (diff)
parent3cec2d693520b8a409a8ba6d2b6d1a40e14ade62 (diff)
downloadrust-b8b2a6503555fc5ea3b7c6516216c95e7b1a19ed.tar.gz
rust-b8b2a6503555fc5ea3b7c6516216c95e7b1a19ed.zip
Rollup merge of #129818 - RalfJung:const-stability, r=compiler-errors
make the const-unstable-in-stable error more clear

The default should be to add `rustc_const_unstable`, not `rustc_allow_const_fn_unstable`.

Also I discovered our check for missing const stability attributes on stable functions -- but strangely that check only kicks in for "reachable" functions. `check_missing_stability` checks for reachability since all reachable functions must have a stability attribute, but I would say if a function has `#[stable]` it should also have const-stability attributes regardless of reachability.
-rw-r--r--compiler/rustc_const_eval/messages.ftl4
-rw-r--r--compiler/rustc_passes/src/stability.rs3
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr4
3 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl
index db788b6b151..8a6dfb89249 100644
--- a/compiler/rustc_const_eval/messages.ftl
+++ b/compiler/rustc_const_eval/messages.ftl
@@ -415,8 +415,8 @@ const_eval_unstable_const_fn = `{$def_path}` is not yet stable as a const fn
 
 const_eval_unstable_in_stable =
     const-stable function cannot use `#[feature({$gate})]`
-    .unstable_sugg = if it is not part of the public API, make this function unstably const
-    .bypass_sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
+    .unstable_sugg = if the function is not (yet) meant to be stable, make this function unstably const
+    .bypass_sugg = otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
 
 const_eval_unterminated_c_string =
     reading a null-terminated string starting at {$pointer} with no null found before end of allocation
diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs
index 4d58590ca3b..ba4c300ea61 100644
--- a/compiler/rustc_passes/src/stability.rs
+++ b/compiler/rustc_passes/src/stability.rs
@@ -544,9 +544,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
         let is_stable =
             self.tcx.lookup_stability(def_id).is_some_and(|stability| stability.level.is_stable());
         let missing_const_stability_attribute = self.tcx.lookup_const_stability(def_id).is_none();
-        let is_reachable = self.effective_visibilities.is_reachable(def_id);
 
-        if is_const && is_stable && missing_const_stability_attribute && is_reachable {
+        if is_const && is_stable && missing_const_stability_attribute {
             let descr = self.tcx.def_descr(def_id.to_def_id());
             self.tcx.dcx().emit_err(errors::MissingConstStabAttr { span, descr });
         }
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
index 019deda063c..cb447719f9c 100644
--- a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
@@ -20,12 +20,12 @@ error: const-stable function cannot use `#[feature(const_refs_to_cell)]`
 LL |     x.get();
    |     ^
    |
-help: if it is not part of the public API, make this function unstably const
+help: if the function is not (yet) meant to be stable, make this function unstably const
    |
 LL + #[rustc_const_unstable(feature = "...", issue = "...")]
 LL | const fn bar3() -> u32 {
    |
-help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
+help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
    |
 LL + #[rustc_allow_const_fn_unstable(const_refs_to_cell)]
 LL | const fn bar3() -> u32 {