Rollup merge of #129659 - RalfJung:const-fn-lang-feat, r=fee1-dead
const fn stability checking: also check declared language features Fixes https://github.com/rust-lang/rust/issues/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`?
This commit is contained in:
commit
ea5bb99c0f
@ -868,9 +868,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
|
|||||||
// Calling an unstable function *always* requires that the corresponding gate
|
// Calling an unstable function *always* requires that the corresponding gate
|
||||||
// (or implied gate) be enabled, even if the function has
|
// (or implied gate) be enabled, even if the function has
|
||||||
// `#[rustc_allow_const_fn_unstable(the_gate)]`.
|
// `#[rustc_allow_const_fn_unstable(the_gate)]`.
|
||||||
let gate_declared = |gate| {
|
let gate_declared = |gate| tcx.features().declared(gate);
|
||||||
tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate)
|
|
||||||
};
|
|
||||||
let feature_gate_declared = gate_declared(gate);
|
let feature_gate_declared = gate_declared(gate);
|
||||||
let implied_gate_declared = implied_by.is_some_and(gate_declared);
|
let implied_gate_declared = implied_by.is_some_and(gate_declared);
|
||||||
if !feature_gate_declared && !implied_gate_declared {
|
if !feature_gate_declared && !implied_gate_declared {
|
||||||
|
@ -3093,10 +3093,7 @@ pub fn is_const_fn(self, def_id: DefId) -> bool {
|
|||||||
Some(stability) if stability.is_const_unstable() => {
|
Some(stability) if stability.is_const_unstable() => {
|
||||||
// has a `rustc_const_unstable` attribute, check whether the user enabled the
|
// has a `rustc_const_unstable` attribute, check whether the user enabled the
|
||||||
// corresponding feature gate.
|
// corresponding feature gate.
|
||||||
self.features()
|
self.features().declared(stability.feature)
|
||||||
.declared_lib_features
|
|
||||||
.iter()
|
|
||||||
.any(|&(sym, _)| sym == stability.feature)
|
|
||||||
}
|
}
|
||||||
// functions without const stability are either stable user written
|
// functions without const stability are either stable user written
|
||||||
// const fn or the user is using feature gates and we thus don't
|
// const fn or the user is using feature gates and we thus don't
|
||||||
|
20
tests/ui/consts/min_const_fn/const-fn-lang-feature.rs
Normal file
20
tests/ui/consts/min_const_fn/const-fn-lang-feature.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
//! Ensure that we can use a language feature with a `const fn`:
|
||||||
|
//! enabling the feature gate actually lets us call the function.
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
#![feature(staged_api, abi_unadjusted)]
|
||||||
|
#![stable(feature = "rust_test", since = "1.0.0")]
|
||||||
|
|
||||||
|
#[unstable(feature = "abi_unadjusted", issue = "42")]
|
||||||
|
#[rustc_const_unstable(feature = "abi_unadjusted", issue = "42")]
|
||||||
|
const fn my_fun() {}
|
||||||
|
|
||||||
|
#[unstable(feature = "abi_unadjusted", issue = "42")]
|
||||||
|
#[rustc_const_unstable(feature = "abi_unadjusted", issue = "42")]
|
||||||
|
const fn my_fun2() {
|
||||||
|
my_fun()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const { my_fun2() };
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user