about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfee1-dead <ent3rm4n@gmail.com>2022-09-26 13:09:42 +0800
committerGitHub <noreply@github.com>2022-09-26 13:09:42 +0800
commitc69edba5151dd368bb1812538b32f4ed56fd9f8b (patch)
tree7e4ff3f74305d521a154e154909afec368aebb30
parentea75178219ab4fd12d035acfc3a0aedb04e91db7 (diff)
parente30b37b84b75dca4622a210ad1ad116d05a1bae9 (diff)
downloadrust-c69edba5151dd368bb1812538b32f4ed56fd9f8b.tar.gz
rust-c69edba5151dd368bb1812538b32f4ed56fd9f8b.zip
Rollup merge of #102197 - Nilstrieb:const-new-🌲, r=Mark-Simulacrum
Stabilize const `BTree{Map,Set}::new`

The FCP was completed in #71835.

Since `len` and `is_empty` are not const stable yet, this also creates a new feature for them since they previously used the same `const_btree_new` feature.
-rw-r--r--clippy_utils/src/qualify_min_const_fn.rs13
-rw-r--r--tests/ui/crashes/ice-7126.rs6
2 files changed, 15 insertions, 4 deletions
diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs
index 405f0228683..f7ce7191772 100644
--- a/clippy_utils/src/qualify_min_const_fn.rs
+++ b/clippy_utils/src/qualify_min_const_fn.rs
@@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
                 // 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`.
                 // as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
+
+                // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` doesn't accept
+                //                  the `-dev` version number so we have to strip it off.
+                let short_version = since
+                    .as_str()
+                    .split('-')
+                    .next()
+                    .expect("rustc_attr::StabilityLevel::Stable::since` is empty");
+
+                let since = rustc_span::Symbol::intern(short_version);
+
                 crate::meets_msrv(
                     msrv,
                     RustcVersion::parse(since.as_str())
-                        .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
+                        .unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")),
                 )
             } else {
                 // Unstable const fn with the feature enabled.
diff --git a/tests/ui/crashes/ice-7126.rs b/tests/ui/crashes/ice-7126.rs
index ca563ba0978..b2dc2248b55 100644
--- a/tests/ui/crashes/ice-7126.rs
+++ b/tests/ui/crashes/ice-7126.rs
@@ -1,13 +1,13 @@
 // This test requires a feature gated const fn and will stop working in the future.
 
-#![feature(const_btree_new)]
+#![feature(const_btree_len)]
 
 use std::collections::BTreeMap;
 
-struct Foo(BTreeMap<i32, i32>);
+struct Foo(usize);
 impl Foo {
     fn new() -> Self {
-        Self(BTreeMap::new())
+        Self(BTreeMap::len(&BTreeMap::<u8, u8>::new()))
     }
 }