diff options
| author | bors <bors@rust-lang.org> | 2021-04-27 14:21:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-27 14:21:11 +0000 |
| commit | 7c7683c8efe447b251d6c5ca6cce51233060f6e8 (patch) | |
| tree | d023a39ece9962e2e691cd2ec6f20e933cbdb2dd | |
| parent | 9af07e65aa3f9f7bf753341fc04f42bcbc43c67e (diff) | |
| parent | db7ad648e7e17eff0f66de2c25c4d581982f981f (diff) | |
| download | rust-7c7683c8efe447b251d6c5ca6cce51233060f6e8.tar.gz rust-7c7683c8efe447b251d6c5ca6cce51233060f6e8.zip | |
Auto merge of #7128 - Jarcho:const_fn_ice, r=flip1995
Fix ICE checking for feature gated const fn fixes: #7126 changelog: Fix ICE in `missing_const_for_fn` when using a feature-gated `const fn`
| -rw-r--r-- | clippy_utils/src/qualify_min_const_fn.rs | 10 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-7126.rs | 14 |
2 files changed, 18 insertions, 6 deletions
diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index b2ce58b597b..a08dcf19e5b 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -364,7 +364,7 @@ fn check_terminator( fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool { rustc_mir::const_eval::is_const_fn(tcx, def_id) - && if let Some(const_stab) = tcx.lookup_const_stability(def_id) { + && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire // 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 .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"), ) } else { - // `rustc_mir::const_eval::is_const_fn` should return false for unstably const functions. - unreachable!(); + // Unstable const fn with the feature enabled. + msrv.is_none() } - } else { - true - } + }) } diff --git a/tests/ui/crashes/ice-7126.rs b/tests/ui/crashes/ice-7126.rs new file mode 100644 index 00000000000..ca563ba0978 --- /dev/null +++ b/tests/ui/crashes/ice-7126.rs @@ -0,0 +1,14 @@ +// This test requires a feature gated const fn and will stop working in the future. + +#![feature(const_btree_new)] + +use std::collections::BTreeMap; + +struct Foo(BTreeMap<i32, i32>); +impl Foo { + fn new() -> Self { + Self(BTreeMap::new()) + } +} + +fn main() {} |
