1
Fork 0

Account for an additional reborrow inserted by UniqueImmBorrow and MutBorrow

This commit is contained in:
Michael Goulet 2024-04-05 17:34:57 -04:00
parent 49c4ebcc40
commit ad0fcac72b
2 changed files with 35 additions and 3 deletions

View file

@ -289,10 +289,15 @@ impl<'tcx> MutVisitor<'tcx> for MakeByMoveBody<'tcx> {
// generating, we also are taking that field by value. Peel off a deref,
// since a layer of reffing has now become redundant.
let final_deref = if needs_deref {
let [mir::ProjectionElem::Deref] = projection else {
bug!("There should only be a single deref for an upvar local initialization");
let Some((mir::ProjectionElem::Deref, projection)) = projection.split_first()
else {
bug!(
"There should be at least a single deref for an upvar local initialization, found {projection:#?}"
);
};
&[]
// There may be more derefs, since we may also implicitly reborrow
// a captured mut pointer.
projection
} else {
projection
};