@@ -55,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
5555 let def_id = body. source . def_id ( ) ;
5656 let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
5757 let move_data = MoveData :: gather_moves ( & body, tcx, param_env, |ty| match ty. kind ( ) {
58+ _ if !ty. needs_drop ( tcx, param_env) => PathFilter :: Skip ,
5859 ty:: Ref ( ..) | ty:: RawPtr ( ..) | ty:: Slice ( _) => PathFilter :: Leaf ,
5960 ty:: Adt ( adt, _) => {
6061 if adt. has_dtor ( tcx) && !adt. is_box ( ) {
@@ -371,7 +372,16 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
371372 let terminator = data. terminator ( ) ;
372373
373374 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+
375385 self . init_data . seek_before ( loc) ;
376386 match self . move_data ( ) . rev_lookup . find ( place. as_ref ( ) ) {
377387 LookupResult :: Exact ( path) => {
@@ -404,18 +414,10 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
404414 bb,
405415 )
406416 }
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 ( ..) => { }
419421 }
420422 }
421423 _ => continue ,
0 commit comments