read_via_copy: don't prematurely optimize away the read
This commit is contained in:
parent
a989e25f1b
commit
7093903ba7
5 changed files with 39 additions and 16 deletions
|
@ -176,23 +176,22 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
} else {
|
||||
span_bug!(terminator.source_info.span, "Only passing a local is supported");
|
||||
};
|
||||
// Add new statement at the end of the block that does the read, and patch
|
||||
// up the terminator.
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
*destination,
|
||||
Rvalue::Use(Operand::Copy(derefed_place)),
|
||||
))),
|
||||
});
|
||||
terminator.kind = match *target {
|
||||
None => {
|
||||
// No target means this read something uninhabited,
|
||||
// so it must be unreachable, and we don't need to
|
||||
// preserve the assignment either.
|
||||
// so it must be unreachable.
|
||||
TerminatorKind::Unreachable
|
||||
}
|
||||
Some(target) => {
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
*destination,
|
||||
Rvalue::Use(Operand::Copy(derefed_place)),
|
||||
))),
|
||||
});
|
||||
TerminatorKind::Goto { target }
|
||||
}
|
||||
Some(target) => TerminatorKind::Goto { target },
|
||||
}
|
||||
}
|
||||
sym::write_via_move => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue