Skip to content

Commit 25aa86d

Browse files
committed
Fix issue rust-lang#43481: emit the EndRegion *before* StorageDeads for a scope.
(The idea is that the StorageDead marks the point where the memory can be deallocated, and the EndRegion is marking where borrows of that memory can no longer legally exist.)
1 parent c3eccc6 commit 25aa86d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustc_mir/build/scope.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
352352
}
353353
let scope = self.scopes.pop().unwrap();
354354
assert_eq!(scope.region_scope, region_scope.0);
355+
356+
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
355357
unpack!(block = build_scope_drops(&mut self.cfg,
356358
&scope,
357359
&self.scopes,
358360
block,
359361
self.arg_count,
360362
false));
361363

362-
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
363364
block.unit()
364365
}
365366

@@ -406,15 +407,16 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
406407
scope.cached_exits.insert((target, region_scope.0), b);
407408
b
408409
};
410+
411+
// End all regions for scopes out of which we are breaking.
412+
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
413+
409414
unpack!(block = build_scope_drops(&mut self.cfg,
410415
scope,
411416
rest,
412417
block,
413418
self.arg_count,
414419
false));
415-
416-
// End all regions for scopes out of which we are breaking.
417-
self.cfg.push_end_region(self.hir.tcx(), block, region_scope.1, scope.region_scope);
418420
}
419421
}
420422
let scope = &self.scopes[len - scope_count];

0 commit comments

Comments
 (0)