about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/check_consts/mod.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-11-02 21:19:21 +0100
committerRalf Jung <post@ralfj.de>2024-11-10 10:16:26 +0100
commite96808162ad7ff5906d7b58d32a25abe139e998c (patch)
tree039f785ca0af8ef506a8b07eac1e1e822ada4917 /compiler/rustc_const_eval/src/check_consts/mod.rs
parent686eeb83e9c6d7f70848cdf84f490f5c1aa3edd3 (diff)
downloadrust-e96808162ad7ff5906d7b58d32a25abe139e998c.tar.gz
rust-e96808162ad7ff5906d7b58d32a25abe139e998c.zip
ensure that all publicly reachable const fn have const stability info
Diffstat (limited to 'compiler/rustc_const_eval/src/check_consts/mod.rs')
-rw-r--r--compiler/rustc_const_eval/src/check_consts/mod.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_const_eval/src/check_consts/mod.rs b/compiler/rustc_const_eval/src/check_consts/mod.rs
index 3b2a79793ae..d49d59c2a08 100644
--- a/compiler/rustc_const_eval/src/check_consts/mod.rs
+++ b/compiler/rustc_const_eval/src/check_consts/mod.rs
@@ -110,14 +110,15 @@ pub fn is_safe_to_expose_on_stable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> b
 
     match tcx.lookup_const_stability(def_id) {
         None => {
-            // Only marked functions can be trusted. Note that this may be a function in a
-            // non-staged-API crate where no recursive checks were done!
-            false
+            // In a `staged_api` crate, we do enforce recursive const stability for all unmarked
+            // functions, so we can trust local functions. But in another crate we don't know which
+            // rules were applied, so we can't trust that.
+            def_id.is_local() && tcx.features().staged_api()
         }
         Some(stab) => {
-            // We consider things safe-to-expose if they are stable, if they don't have any explicit
-            // const stability attribute, or if they are marked as `const_stable_indirect`.
-            stab.is_const_stable() || stab.feature.is_none() || stab.const_stable_indirect
+            // We consider things safe-to-expose if they are stable or if they are marked as
+            // `const_stable_indirect`.
+            stab.is_const_stable() || stab.const_stable_indirect
         }
     }
 }