Skip to content

Commit 4a3d002

Browse files
committed
Auto merge of #118416 - aDotInTheVoid:const-stable-diag, r=<try>
[WIP] const-stabilize Hash{Map/Set}::new Extremely normal, nothing to see here. r? `@ghost`
2 parents 5facb42 + 15605a9 commit 4a3d002

File tree

7 files changed

+40
-9
lines changed

7 files changed

+40
-9
lines changed

compiler/rustc_const_eval/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ const_eval_unreachable_unwind =
385385
const_eval_unsigned_offset_from_overflow =
386386
`ptr_offset_from_unsigned` called when first pointer has smaller offset than second: {$a_offset} < {$b_offset}
387387
const_eval_unsized_local = unsized locals are not supported
388+
388389
const_eval_unstable_const_fn = `{$def_path}` is not yet stable as a const fn
390+
const_eval_unstable_declared_here = `{$def_path}` declared unstable here
389391
390392
const_eval_unstable_in_stable =
391393
const-stable function cannot use `#[feature({$gate})]`

compiler/rustc_const_eval/src/errors.rs

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub(crate) struct UnstableConstFn {
129129
#[primary_span]
130130
pub span: Span,
131131
pub def_path: String,
132+
133+
#[label(const_eval_unstable_declared_here)]
134+
pub declared: Span,
132135
}
133136

134137
#[derive(Diagnostic)]

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");

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
339339
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
340340
let FnCallUnstable(def_id, feature) = *self;
341341

342-
let mut err = ccx
343-
.tcx
344-
.sess
345-
.create_err(errors::UnstableConstFn { span, def_path: ccx.tcx.def_path_str(def_id) });
342+
let mut err = ccx.tcx.sess.create_err(errors::UnstableConstFn {
343+
span,
344+
def_path: ccx.tcx.def_path_str(def_id),
345+
declared: ccx.tcx.def_span(def_id),
346+
});
346347

347348
if ccx.is_const_stable_const_fn() {
348349
err.help("const-stable functions can only call other const-stable functions");

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)