Skip to content

Commit 7c7683c

Browse files
committed
Auto merge of rust-lang#7128 - Jarcho:const_fn_ice, r=flip1995
Fix ICE checking for feature gated const fn fixes: rust-lang#7126 changelog: Fix ICE in `missing_const_for_fn` when using a feature-gated `const fn`
2 parents 9af07e6 + db7ad64 commit 7c7683c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

clippy_utils/src/qualify_min_const_fn.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn check_terminator(
364364

365365
fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool {
366366
rustc_mir::const_eval::is_const_fn(tcx, def_id)
367-
&& if let Some(const_stab) = tcx.lookup_const_stability(def_id) {
367+
&& tcx.lookup_const_stability(def_id).map_or(true, |const_stab| {
368368
if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level {
369369
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
370370
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
@@ -375,10 +375,8 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> b
375375
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
376376
)
377377
} else {
378-
// `rustc_mir::const_eval::is_const_fn` should return false for unstably const functions.
379-
unreachable!();
378+
// Unstable const fn with the feature enabled.
379+
msrv.is_none()
380380
}
381-
} else {
382-
true
383-
}
381+
})
384382
}

tests/ui/crashes/ice-7126.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This test requires a feature gated const fn and will stop working in the future.
2+
3+
#![feature(const_btree_new)]
4+
5+
use std::collections::BTreeMap;
6+
7+
struct Foo(BTreeMap<i32, i32>);
8+
impl Foo {
9+
fn new() -> Self {
10+
Self(BTreeMap::new())
11+
}
12+
}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)