@@ -54,7 +54,8 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
54
54
55
55
let def_id = body. source . def_id ( ) ;
56
56
let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
57
- let move_data = MoveData :: gather_moves ( & body, tcx, param_env, |_| true ) ;
57
+ let move_data =
58
+ MoveData :: gather_moves ( & body, tcx, param_env, |ty| ty. needs_drop ( tcx, param_env) ) ;
58
59
let elaborate_patch = {
59
60
let env = MoveDataParamEnv { move_data, param_env } ;
60
61
@@ -340,7 +341,16 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
340
341
let terminator = data. terminator ( ) ;
341
342
342
343
match terminator. kind {
343
- TerminatorKind :: Drop { place, target, unwind, replace } => {
344
+ TerminatorKind :: Drop { place, target, unwind, replace : _ } => {
345
+ if !place
346
+ . ty ( & self . body . local_decls , self . tcx )
347
+ . ty
348
+ . needs_drop ( self . tcx , self . env . param_env )
349
+ {
350
+ self . patch . patch_terminator ( bb, TerminatorKind :: Goto { target } ) ;
351
+ continue ;
352
+ }
353
+
344
354
self . init_data . seek_before ( loc) ;
345
355
match self . move_data ( ) . rev_lookup . find ( place. as_ref ( ) ) {
346
356
LookupResult :: Exact ( path) => {
@@ -373,18 +383,10 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
373
383
bb,
374
384
)
375
385
}
376
- LookupResult :: Parent ( ..) => {
377
- if !replace {
378
- self . tcx . sess . delay_span_bug (
379
- terminator. source_info . span ,
380
- format ! ( "drop of untracked value {bb:?}" ) ,
381
- ) ;
382
- }
383
- // A drop and replace behind a pointer/array/whatever.
384
- // The borrow checker requires that these locations are initialized before the assignment,
385
- // so we just leave an unconditional drop.
386
- assert ! ( !data. is_cleanup) ;
387
- }
386
+ // A drop and replace behind a pointer/array/whatever.
387
+ // The borrow checker requires that these locations are initialized before the assignment,
388
+ // so we just leave an unconditional drop.
389
+ LookupResult :: Parent ( ..) => { }
388
390
}
389
391
}
390
392
_ => continue ,
0 commit comments