Skip to content

Commit 19f8a9d

Browse files
committed
Boxes can also use the fast path
1 parent c847071 commit 19f8a9d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/stacked_borrows.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -623,18 +623,19 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for MiriEvalContext<'a, 'mir, 'tcx> {
623623
// We need a visitor to visit all references. However, that requires
624624
// a `MemPlace`, so we have a fast path for reference types that
625625
// avoids allocating.
626-
match place.layout.ty.sty {
627-
// Cannot use `builtin_deref` because that reports *immutable* for `Box`,
628-
// making it useless.
629-
ty::Ref(_, _, mutbl) => {
630-
// fast path
631-
let val = self.read_immediate(self.place_to_op(place)?)?;
632-
let val = self.retag_reference(val, mutbl)?;
633-
self.write_immediate(val, place)?;
634-
return Ok(());
635-
}
636-
_ => {}, // handled with the general case below
637-
};
626+
// Cannot use `builtin_deref` because that reports *immutable* for `Box`,
627+
// making it useless.
628+
if let Some(mutbl) = match place.layout.ty.sty {
629+
ty::Ref(_, _, mutbl) => Some(mutbl),
630+
ty::Adt(..) if place.layout.ty.is_box() => Some(MutMutable),
631+
_ => None, // handled with the general case below
632+
} {
633+
// fast path
634+
let val = self.read_immediate(self.place_to_op(place)?)?;
635+
let val = self.retag_reference(val, mutbl)?;
636+
self.write_immediate(val, place)?;
637+
return Ok(());
638+
}
638639
let place = self.force_allocation(place)?;
639640

640641
let mut visitor = RetagVisitor { ecx: self };

0 commit comments

Comments
 (0)