Skip to content

Commit 7b783a0

Browse files
authored
Unrolled build for rust-lang#129659
Rollup merge of rust-lang#129659 - RalfJung:const-fn-lang-feat, r=fee1-dead const fn stability checking: also check declared language features Fixes rust-lang#129656 `@oli-obk` I assume it is just an oversight that this didn't use `features().declared()`? Or is there a deep reason that this must only check `declared_lib_features`?
2 parents 9649706 + c298417 commit 7b783a0

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-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
@@ -3093,10 +3093,7 @@ impl<'tcx> TyCtxt<'tcx> {
30933093
Some(stability) if stability.is_const_unstable() => {
30943094
// has a `rustc_const_unstable` attribute, check whether the user enabled the
30953095
// corresponding feature gate.
3096-
self.features()
3097-
.declared_lib_features
3098-
.iter()
3099-
.any(|&(sym, _)| sym == stability.feature)
3096+
self.features().declared(stability.feature)
31003097
}
31013098
// functions without const stability are either stable user written
31023099
// 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,20 @@
1+
//! Ensure that we can use a language feature with a `const fn`:
2+
//! enabling the feature gate actually lets us call the function.
3+
//@ check-pass
4+
5+
#![feature(staged_api, abi_unadjusted)]
6+
#![stable(feature = "rust_test", since = "1.0.0")]
7+
8+
#[unstable(feature = "abi_unadjusted", issue = "42")]
9+
#[rustc_const_unstable(feature = "abi_unadjusted", issue = "42")]
10+
const fn my_fun() {}
11+
12+
#[unstable(feature = "abi_unadjusted", issue = "42")]
13+
#[rustc_const_unstable(feature = "abi_unadjusted", issue = "42")]
14+
const fn my_fun2() {
15+
my_fun()
16+
}
17+
18+
fn main() {
19+
const { my_fun2() };
20+
}

0 commit comments

Comments
 (0)