From a05c37c1f9a4e2ce9e04a78053287dbf3bdb9639 Mon Sep 17 00:00:00 2001 From: beetrees Date: Wed, 28 Aug 2024 05:47:44 +0100 Subject: [PATCH] Fix using lang features in `#[rustc_const_unstable]` --- .../rustc_const_eval/src/check_consts/check.rs | 4 +--- .../const-stability-lang-feature.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 tests/ui/stability-attribute/const-stability-lang-feature.rs diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 6a086a3a7e5a0..7cfb101399daa 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -868,9 +868,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { // Calling an unstable function *always* requires that the corresponding gate // (or implied gate) be enabled, even if the function has // `#[rustc_allow_const_fn_unstable(the_gate)]`. - let gate_declared = |gate| { - tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate) - }; + let gate_declared = |gate| tcx.features().declared(gate); let feature_gate_declared = gate_declared(gate); let implied_gate_declared = implied_by.is_some_and(gate_declared); if !feature_gate_declared && !implied_gate_declared { diff --git a/tests/ui/stability-attribute/const-stability-lang-feature.rs b/tests/ui/stability-attribute/const-stability-lang-feature.rs new file mode 100644 index 0000000000000..fb6ccc6dc8797 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-lang-feature.rs @@ -0,0 +1,15 @@ +//@ check-pass + +#![crate_type = "lib"] +#![feature(staged_api)] +#![unstable(feature = "staged_api", issue = "none")] + +#[unstable(feature = "staged_api", issue = "none")] +#[rustc_const_unstable(feature = "staged_api", issue = "none")] +const fn callee() {} + +#[unstable(feature = "staged_api", issue = "none")] +#[rustc_const_unstable(feature = "staged_api", issue = "none")] +const fn caller() { + callee(); +}