Skip to content

Commit 79dd70f

Browse files
committed
Stacked Borrows: don't read from memory during retagging
1 parent 283928a commit 79dd70f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/helpers.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,23 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
222222
// This is `Freeze`, there cannot be an `UnsafeCell`
223223
Ok(())
224224
} else {
225-
// Proceed further
226-
self.walk_value(v)
225+
// We want to not actually read from memory for this visit. So, before
226+
// walking this value, we have to make sure it is not a
227+
// `Variants::Multiple`.
228+
match v.layout.variants {
229+
layout::Variants::Multiple { .. } => {
230+
// A multi-variant enum, or generator, or so.
231+
// Treat this like a union: without reading from memory,
232+
// we cannot determine the variant we are in. Reading from
233+
// memory would be subject to Stacked Borrows rules, leading
234+
// to all sorts of "funny" recursion.
235+
self.visit_union(v)
236+
}
237+
layout::Variants::Single { .. } => {
238+
// Proceed further
239+
self.walk_value(v)
240+
}
241+
}
227242
}
228243
}
229244

0 commit comments

Comments
 (0)