Skip to content

Commit 33076f5

Browse files
committed
const fn stability checking: also check declared language features
1 parent bf662eb commit 33076f5

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
868868
// Calling an unstable function *always* requires that the corresponding gate
869869
// (or implied gate) be enabled, even if the function has
870870
// `#[rustc_allow_const_fn_unstable(the_gate)]`.
871-
let gate_declared = |gate| {
872-
tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate)
873-
};
871+
let gate_declared = |gate| tcx.features().declared(gate);
874872
let feature_gate_declared = gate_declared(gate);
875873
let implied_gate_declared = implied_by.is_some_and(gate_declared);
876874
if !feature_gate_declared && !implied_gate_declared {

compiler/rustc_middle/src/ty/context.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3089,10 +3089,7 @@ impl<'tcx> TyCtxt<'tcx> {
30893089
Some(stability) if stability.is_const_unstable() => {
30903090
// has a `rustc_const_unstable` attribute, check whether the user enabled the
30913091
// corresponding feature gate.
3092-
self.features()
3093-
.declared_lib_features
3094-
.iter()
3095-
.any(|&(sym, _)| sym == stability.feature)
3092+
self.features().declared(stability.feature)
30963093
}
30973094
// functions without const stability are either stable user written
30983095
// const fn or the user is using feature gates and we thus don't
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Ensure that we can use a language feature with a `const fn` and things behave as expected.
2+
//@ check-pass
3+
4+
#![feature(staged_api, abi_unadjusted)]
5+
#![stable(feature = "rust_test", since = "1.0.0")]
6+
7+
#[unstable(feature = "abi_unadjusted", issue = "42")]
8+
#[rustc_const_unstable(feature = "abi_unadjusted", issue = "42")]
9+
const fn my_fun() {}
10+
11+
#[unstable(feature = "abi_unadjusted", issue = "42")]
12+
#[rustc_const_unstable(feature = "abi_unadjusted", issue = "42")]
13+
const fn my_fun2() {
14+
my_fun()
15+
}
16+
17+
fn main() {
18+
const { my_fun2() };
19+
}

0 commit comments

Comments
 (0)