Skip to content

Commit 804c2c1

Browse files
authored
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.
2 parents 0cee03d + 66484c0 commit 804c2c1

File tree

8 files changed

+24
-15
lines changed

8 files changed

+24
-15
lines changed

compiler/rustc_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
#![feature(associated_type_defaults)]
66
#![feature(closure_track_caller)]
7-
#![feature(const_btree_new)]
7+
#![feature(const_btree_len)]
88
#![cfg_attr(bootstrap, feature(let_else))]
99
#![feature(once_cell)]
1010
#![feature(min_specialization)]

library/alloc/src/collections/btree/map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<K, V> BTreeMap<K, V> {
580580
/// map.insert(1, "a");
581581
/// ```
582582
#[stable(feature = "rust1", since = "1.0.0")]
583-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
583+
#[rustc_const_stable(feature = "const_btree_new", since = "CURRENT_RUSTC_VERSION")]
584584
#[must_use]
585585
pub const fn new() -> BTreeMap<K, V> {
586586
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(Global), _marker: PhantomData }
@@ -2392,7 +2392,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
23922392
/// ```
23932393
#[must_use]
23942394
#[stable(feature = "rust1", since = "1.0.0")]
2395-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
2395+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
23962396
pub const fn len(&self) -> usize {
23972397
self.length
23982398
}
@@ -2413,7 +2413,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
24132413
/// ```
24142414
#[must_use]
24152415
#[stable(feature = "rust1", since = "1.0.0")]
2416-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
2416+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
24172417
pub const fn is_empty(&self) -> bool {
24182418
self.len() == 0
24192419
}

library/alloc/src/collections/btree/set.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl<T> BTreeSet<T> {
343343
/// let mut set: BTreeSet<i32> = BTreeSet::new();
344344
/// ```
345345
#[stable(feature = "rust1", since = "1.0.0")]
346-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
346+
#[rustc_const_stable(feature = "const_btree_new", since = "CURRENT_RUSTC_VERSION")]
347347
#[must_use]
348348
pub const fn new() -> BTreeSet<T> {
349349
BTreeSet { map: BTreeMap::new() }
@@ -1174,7 +1174,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
11741174
/// ```
11751175
#[must_use]
11761176
#[stable(feature = "rust1", since = "1.0.0")]
1177-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
1177+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
11781178
pub const fn len(&self) -> usize {
11791179
self.map.len()
11801180
}
@@ -1193,7 +1193,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
11931193
/// ```
11941194
#[must_use]
11951195
#[stable(feature = "rust1", since = "1.0.0")]
1196-
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
1196+
#[rustc_const_unstable(feature = "const_btree_len", issue = "71835")]
11971197
pub const fn is_empty(&self) -> bool {
11981198
self.len() == 0
11991199
}

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
#![feature(coerce_unsized)]
100100
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
101101
#![feature(const_box)]
102-
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
102+
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
103103
#![feature(const_cow_is_borrowed)]
104104
#![feature(const_convert)]
105105
#![feature(const_size_of_val)]

library/alloc/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#![feature(slice_group_by)]
3333
#![feature(slice_partition_dedup)]
3434
#![feature(string_remove_matches)]
35-
#![feature(const_btree_new)]
35+
#![feature(const_btree_len)]
3636
#![feature(const_default_impls)]
3737
#![feature(const_trait_impl)]
3838
#![feature(const_str_from_utf8)]

src/test/ui/consts/issue-88071.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//
33
// regression test for #88071
44

5-
#![feature(const_btree_new)]
6-
75
use std::collections::BTreeMap;
86

97
pub struct CustomMap<K, V>(BTreeMap<K, V>);

src/tools/clippy/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.

src/tools/clippy/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)