5
5
//! `TypingMode::PostAnalysis` to provide more precise type information, especially about opaque
6
6
//! types.
7
7
8
+ use rustc_hir:: LangItem ;
8
9
use rustc_middle:: mir:: * ;
9
10
use rustc_middle:: ty:: TyCtxt ;
10
11
use tracing:: { debug, trace} ;
@@ -21,15 +22,25 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveUnneededDrops {
21
22
let mut should_simplify = false ;
22
23
for block in body. basic_blocks . as_mut ( ) {
23
24
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)
28
28
}
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 ;
32
40
}
41
+ debug ! ( "SUCCESS: replacing `drop` with goto({:?})" , target) ;
42
+ terminator. kind = TerminatorKind :: Goto { target } ;
43
+ should_simplify = true ;
33
44
}
34
45
35
46
// if we applied optimizations, we potentially have some cfg to cleanup to
0 commit comments