Skip to content

Commit c94769a

Browse files
oli-obkRalfJung
andauthored
Clarify order of operations during interning
Co-authored-by: Ralf Jung <[email protected]>
1 parent 5d46b98 commit c94769a

File tree

1 file changed

+7
-0
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+7
-0
lines changed

compiler/rustc_const_eval/src/interpret/intern.rs

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ pub fn intern_const_alloc_recursive<
148148
// better errors. Maybe we should consider doing validation before interning in the future.
149149
while let Some(prov) = todo.pop() {
150150
let alloc_id = prov.alloc_id();
151+
// Crucially, we check this *before* checking whether the `alloc_id`
152+
// has already been interned. The point of this check is to ensure that when
153+
// there are multiple pointers to the same allocation, they are *all* immutable.
154+
// Therefore it would be bad if we only checked the first pointer to any given
155+
// allocation.
156+
// (It is likely not possible to actually have multiple pointers to the same allocation,
157+
// so alternatively we could also check that and ICE if there are multiple such pointers.)
151158
if intern_kind != InternKind::Promoted
152159
&& inner_mutability == Mutability::Not
153160
&& !prov.immutable()

0 commit comments

Comments
 (0)