Skip to content

Commit 2dd6fb2

Browse files
authored
Rollup merge of #142288 - RalfJung:const-eval-comments, r=oli-obk
const_eval: fix some outdated comments r? `@oli-obk`
2 parents ea92207 + 6d1db11 commit 2dd6fb2

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
356356
hir::ConstContext::ConstFn => true,
357357
_ => {
358358
// For indirect places, we are not creating a new permanent borrow, it's just as
359-
// transient as the already existing one. For reborrowing references this is handled
360-
// at the top of `visit_rvalue`, but for raw pointers we handle it here.
361-
// Pointers/references to `static mut` and cases where the `*` is not the first
362-
// projection also end up here.
359+
// transient as the already existing one.
363360
// Locals with StorageDead do not live beyond the evaluation and can
364361
// thus safely be borrowed without being able to be leaked to the final
365362
// value of the constant.

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,11 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx, const_eval
227227

228228
// Keep interning as long as there are things to intern.
229229
// We show errors if there are dangling pointers, or mutable pointers in immutable contexts
230-
// (i.e., everything except for `static mut`). When these errors affect references, it is
231-
// unfortunate that we show these errors here and not during validation, since validation can
232-
// show much nicer errors. However, we do need these checks to be run on all pointers, including
233-
// raw pointers, so we cannot rely on validation to catch them -- and since interning runs
234-
// before validation, and interning doesn't know the type of anything, this means we can't show
235-
// better errors. Maybe we should consider doing validation before interning in the future.
230+
// (i.e., everything except for `static mut`). We only return these errors as a `Result`
231+
// so that the caller can run validation, and subsequently only report interning errors
232+
// if validation fails. Validation has the better error messages so we prefer those, but
233+
// interning has better coverage since it "sees" *all* pointers, including raw pointers and
234+
// references stored in unions.
236235
while let Some(prov) = todo.pop() {
237236
trace!(?prov);
238237
let alloc_id = prov.alloc_id();
@@ -279,12 +278,12 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx, const_eval
279278
// when there is memory there that someone might expect to be mutable, but we make it immutable.
280279
let dangling = !is_already_global && !ecx.memory.alloc_map.contains_key(&alloc_id);
281280
if !dangling {
282-
// Found a mutable reference inside a const where inner allocations should be
281+
// Found a mutable pointer inside a const where inner allocations should be
283282
// immutable.
284283
if !ecx.tcx.sess.opts.unstable_opts.unleash_the_miri_inside_of_you {
285284
span_bug!(
286285
ecx.tcx.span,
287-
"the static const safety checks accepted mutable references they should not have accepted"
286+
"the static const safety checks accepted a mutable pointer they should not have accepted"
288287
);
289288
}
290289
// Prefer dangling pointer errors over mutable pointer errors

0 commit comments

Comments
 (0)