@@ -55,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
55
55
let def_id = body. source . def_id ( ) ;
56
56
let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
57
57
let move_data = MoveData :: gather_moves ( & body, tcx, param_env, |ty| match ty. kind ( ) {
58
+ _ if !ty. needs_drop ( tcx, param_env) => PathFilter :: Skip ,
58
59
ty:: Ref ( ..) | ty:: RawPtr ( ..) | ty:: Slice ( _) => PathFilter :: Leaf ,
59
60
ty:: Adt ( adt, _) => {
60
61
if adt. has_dtor ( tcx) && !adt. is_box ( ) {
@@ -371,7 +372,16 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
371
372
let terminator = data. terminator ( ) ;
372
373
373
374
match terminator. kind {
374
- TerminatorKind :: Drop { place, target, unwind, replace } => {
375
+ TerminatorKind :: Drop { place, target, unwind, replace : _ } => {
376
+ if !place
377
+ . ty ( & self . body . local_decls , self . tcx )
378
+ . ty
379
+ . needs_drop ( self . tcx , self . env . param_env )
380
+ {
381
+ self . patch . patch_terminator ( bb, TerminatorKind :: Goto { target } ) ;
382
+ continue ;
383
+ }
384
+
375
385
self . init_data . seek_before ( loc) ;
376
386
match self . move_data ( ) . rev_lookup . find ( place. as_ref ( ) ) {
377
387
LookupResult :: Exact ( path) => {
@@ -404,18 +414,10 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
404
414
bb,
405
415
)
406
416
}
407
- LookupResult :: Parent ( ..) => {
408
- if !replace {
409
- self . tcx . sess . delay_span_bug (
410
- terminator. source_info . span ,
411
- format ! ( "drop of untracked value {bb:?}" ) ,
412
- ) ;
413
- }
414
- // A drop and replace behind a pointer/array/whatever.
415
- // The borrow checker requires that these locations are initialized before the assignment,
416
- // so we just leave an unconditional drop.
417
- assert ! ( !data. is_cleanup) ;
418
- }
417
+ // A drop and replace behind a pointer/array/whatever.
418
+ // The borrow checker requires that these locations are initialized before the assignment,
419
+ // so we just leave an unconditional drop.
420
+ LookupResult :: Parent ( ..) => { }
419
421
}
420
422
}
421
423
_ => continue ,
0 commit comments