Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/analyze/local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,12 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {

fn unelaborate_derefs(&mut self) {
let mut v = analyze::ReplacePlacesVisitor::new(self.tcx);
for (block, data) in self.body.basic_blocks.clone().iter_enumerated() {
for (idx, _stmt) in data.statements.iter().enumerate() {
// A deref temp must be replaced in every block that uses it, and block indices do not
// follow dominance: drop elaboration can number a cleanup block before the one that
// defines the temp it uses.
for block in self.body.basic_blocks.reverse_postorder().to_vec() {
let statement_count = self.body.basic_blocks[block].statements.len();
for idx in 0..statement_count {
let stmt =
&mut self.body.basic_blocks.as_mut().as_mut_slice()[block].statements[idx];
v.visit_statement(stmt);
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/fail/box_move_out_after_call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@error-in-other-file: Unsat
//@compile-flags: -C debug-assertions=off

fn add(bb: Box<Box<i64>>, x: i64) -> i64 {
let c = Box::new(x);
let inner = *bb;
*inner + *c
}

fn main() {
assert!(add(Box::new(Box::new(1)), 2) == 4);
}
12 changes: 12 additions & 0 deletions tests/ui/pass/box_move_out_after_call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@check-pass
//@compile-flags: -C debug-assertions=off

fn add(bb: Box<Box<i64>>, x: i64) -> i64 {
let c = Box::new(x);
let inner = *bb;
*inner + *c
}

fn main() {
assert!(add(Box::new(Box::new(1)), 2) == 3);
}
Loading