Skip to content

Commit 538cd1e

Browse files
committed
Auto merge of #118423 - aDotInTheVoid:const-stabilize-2, r=<try>
[WIP] const-stabilize Hash{Map/Set}::new Like #118416, but without the random compiler changes to debug this. I want to see if this works on CI before figuring out if the hacks are permissible. r? `@ghost`
2 parents 5facb42 + 139dd27 commit 538cd1e

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
992992
// `extern` functions, and these have no way to get marked `const`. So instead we
993993
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
994994
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
995-
self.check_op(ops::FnCallUnstable(callee, None));
996-
return;
995+
if !super::rustc_allow_const_fn_unstable(tcx, caller, sym::any) {
996+
self.check_op(ops::FnCallUnstable(callee, None));
997+
return;
998+
}
997999
}
9981000
}
9991001
trace!("permitting call");

library/std/src/collections/hash/map.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,18 @@ impl<K, V, S> HashMap<K, V, S> {
279279
/// ```
280280
#[inline]
281281
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
282-
#[rustc_const_unstable(feature = "const_collections_with_hasher", issue = "102575")]
282+
#[cfg_attr(
283+
bootstrap,
284+
rustc_const_unstable(feature = "const_collections_with_hasher", issue = "102575")
285+
)]
286+
#[cfg_attr(
287+
not(bootstrap),
288+
rustc_const_stable(
289+
feature = "const_collections_with_hasher",
290+
since = "CURRENT_RUSTC_VERSION"
291+
)
292+
)]
293+
#[rustc_allow_const_fn_unstable(any)]
283294
pub const fn with_hasher(hash_builder: S) -> HashMap<K, V, S> {
284295
HashMap { base: base::HashMap::with_hasher(hash_builder) }
285296
}

library/std/src/collections/hash/set.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,18 @@ impl<T, S> HashSet<T, S> {
369369
/// ```
370370
#[inline]
371371
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
372-
#[rustc_const_unstable(feature = "const_collections_with_hasher", issue = "102575")]
372+
#[cfg_attr(
373+
bootstrap,
374+
rustc_const_unstable(feature = "const_collections_with_hasher", issue = "102575")
375+
)]
376+
#[cfg_attr(
377+
not(bootstrap),
378+
rustc_const_stable(
379+
feature = "const_collections_with_hasher",
380+
since = "CURRENT_RUSTC_VERSION"
381+
)
382+
)]
383+
#[rustc_allow_const_fn_unstable(any)]
373384
pub const fn with_hasher(hasher: S) -> HashSet<T, S> {
374385
HashSet { base: base::HashSet::with_hasher(hasher) }
375386
}

library/std/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
#![feature(no_sanitize)]
298298
#![feature(platform_intrinsics)]
299299
#![feature(prelude_import)]
300+
#![feature(rustc_allow_const_fn_unstable)]
300301
#![feature(rustc_attrs)]
301302
#![feature(rustdoc_internals)]
302303
#![feature(staged_api)]
@@ -308,6 +309,7 @@
308309
//
309310
// Library features (core):
310311
// tidy-alphabetical-start
312+
#![cfg_attr(bootstrap, feature(const_collections_with_hasher))]
311313
#![feature(char_internals)]
312314
#![feature(core_intrinsics)]
313315
#![feature(core_io_borrowed_buf)]
@@ -388,7 +390,6 @@
388390
//
389391
// Only for const-ness:
390392
// tidy-alphabetical-start
391-
#![feature(const_collections_with_hasher)]
392393
#![feature(const_hash)]
393394
#![feature(const_io_structs)]
394395
#![feature(const_ip)]

0 commit comments

Comments
 (0)