Skip to content

Commit c69edba

Browse files
authored
Rollup merge of rust-lang#102197 - Nilstrieb:const-new-🌲, r=Mark-Simulacrum
Stabilize const `BTree{Map,Set}::new` The FCP was completed in rust-lang#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.
2 parents ea75178 + e30b37b commit c69edba

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

‎clippy_utils/src/qualify_min_const_fn.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,21 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
367367
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
368368
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
369369
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
370+
371+
// HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver` doesn't accept
372+
// the `-dev` version number so we have to strip it off.
373+
let short_version = since
374+
.as_str()
375+
.split('-')
376+
.next()
377+
.expect("rustc_attr::StabilityLevel::Stable::since` is empty");
378+
379+
let since = rustc_span::Symbol::intern(short_version);
380+
370381
crate::meets_msrv(
371382
msrv,
372383
RustcVersion::parse(since.as_str())
373-
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
384+
.unwrap_or_else(|err| panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")),
374385
)
375386
} else {
376387
// Unstable const fn with the feature enabled.

‎tests/ui/crashes/ice-7126.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// This test requires a feature gated const fn and will stop working in the future.
22

3-
#![feature(const_btree_new)]
3+
#![feature(const_btree_len)]
44

55
use std::collections::BTreeMap;
66

7-
struct Foo(BTreeMap<i32, i32>);
7+
struct Foo(usize);
88
impl Foo {
99
fn new() -> Self {
10-
Self(BTreeMap::new())
10+
Self(BTreeMap::len(&BTreeMap::<u8, u8>::new()))
1111
}
1212
}
1313

0 commit comments

Comments
 (0)