@@ -233,6 +233,35 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
233
233
fn terminator_effect ( & self ,
234
234
sets : & mut BlockSets < BorrowIndex > ,
235
235
location : Location ) {
236
+ let block = & self . mir . basic_blocks ( ) . get ( location. block ) . unwrap_or_else ( || {
237
+ panic ! ( "could not find block at location {:?}" , location) ;
238
+ } ) ;
239
+ match block. terminator ( ) . kind {
240
+ mir:: TerminatorKind :: Resume |
241
+ mir:: TerminatorKind :: Return |
242
+ mir:: TerminatorKind :: GeneratorDrop => {
243
+ // When we return from the function, then all `ReScope`-style regions
244
+ // are guaranteed to have ended.
245
+ // Normally, there would be `EndRegion` statements that come before,
246
+ // and hence most of these loans will already be dead -- but, in some cases
247
+ // like unwind paths, we do not always emit `EndRegion` statements, so we
248
+ // add some kills here as a "backup" and to avoid spurious error messages.
249
+ for ( borrow_index, borrow_data) in self . borrows . iter_enumerated ( ) {
250
+ if let ReScope ( ..) = borrow_data. region {
251
+ sets. kill ( & borrow_index) ;
252
+ }
253
+ }
254
+ }
255
+ mir:: TerminatorKind :: SwitchInt { ..} |
256
+ mir:: TerminatorKind :: Drop { ..} |
257
+ mir:: TerminatorKind :: DropAndReplace { ..} |
258
+ mir:: TerminatorKind :: Call { ..} |
259
+ mir:: TerminatorKind :: Assert { ..} |
260
+ mir:: TerminatorKind :: Yield { ..} |
261
+ mir:: TerminatorKind :: Goto { ..} |
262
+ mir:: TerminatorKind :: FalseEdges { ..} |
263
+ mir:: TerminatorKind :: Unreachable => { }
264
+ }
236
265
self . kill_loans_out_of_scope_at_location ( sets, location) ;
237
266
}
238
267
0 commit comments