55//! `TypingMode::PostAnalysis` to provide more precise type information, especially about opaque 
66//! types. 
77
8+ use  rustc_hir:: LangItem ; 
89use  rustc_middle:: mir:: * ; 
910use  rustc_middle:: ty:: TyCtxt ; 
1011use  tracing:: { debug,  trace} ; 
@@ -21,15 +22,25 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveUnneededDrops {
2122        let  mut  should_simplify = false ; 
2223        for  block in  body. basic_blocks . as_mut ( )  { 
2324            let  terminator = block. terminator_mut ( ) ; 
24-             if  let  TerminatorKind :: Drop  {  place,  target,  .. }  = terminator. kind  { 
25-                 let  ty = place. ty ( & body. local_decls ,  tcx) ; 
26-                 if  ty. ty . needs_drop ( tcx,  typing_env)  { 
27-                     continue ; 
25+             let  ( ty,  target)  = match  terminator. kind  { 
26+                 TerminatorKind :: Drop  {  place,  target,  .. }  => { 
27+                     ( place. ty ( & body. local_decls ,  tcx) . ty ,  target) 
2828                } 
29-                 debug ! ( "SUCCESS: replacing `drop` with goto({:?})" ,  target) ; 
30-                 terminator. kind  = TerminatorKind :: Goto  {  target } ; 
31-                 should_simplify = true ; 
29+                 TerminatorKind :: Call  {  ref  func,  target :  Some ( target) ,  .. } 
30+                     if  let  Some ( ( def_id,  generics) )  = func. const_fn_def ( ) 
31+                         && tcx. is_lang_item ( def_id,  LangItem :: DropInPlace )  =>
32+                 { 
33+                     ( generics. type_at ( 0 ) ,  target) 
34+                 } 
35+                 _ => continue , 
36+             } ; 
37+ 
38+             if  ty. needs_drop ( tcx,  typing_env)  { 
39+                 continue ; 
3240            } 
41+             debug ! ( "SUCCESS: replacing `drop` with goto({:?})" ,  target) ; 
42+             terminator. kind  = TerminatorKind :: Goto  {  target } ; 
43+             should_simplify = true ; 
3344        } 
3445
3546        // if we applied optimizations, we potentially have some cfg to cleanup to 
0 commit comments