@@ -12,6 +12,7 @@ const CONST_SWITCH_BONUS: usize = 10;
12
12
const MULTIPLE_MUT_PENALTY : usize = 50 ;
13
13
const REF_COPY_BONUS : usize = 5 ;
14
14
const MANY_PARAMETERS_BONUS : usize = 10 ;
15
+ const REMOVABLE_DROP_BONUS : usize = 20 ;
15
16
16
17
/// Verify that the callee body is compatible with the caller.
17
18
#[ derive( Clone ) ]
@@ -156,13 +157,16 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
156
157
fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , _: Location ) {
157
158
match & terminator. kind {
158
159
TerminatorKind :: Drop { place, unwind, .. } => {
159
- // If the place doesn't actually need dropping, treat it like a regular goto.
160
160
let ty = self . instantiate_ty ( place. ty ( self . callee_body , self . tcx ) . ty ) ;
161
161
if ty. needs_drop ( self . tcx , self . param_env ) {
162
162
self . penalty += CALL_PENALTY ;
163
163
if let UnwindAction :: Cleanup ( _) = unwind {
164
164
self . penalty += LANDINGPAD_PENALTY ;
165
165
}
166
+ } else {
167
+ // If the place doesn't actually need dropping,
168
+ // we'd like to inline it to simplify the CFG
169
+ self . bonus += REMOVABLE_DROP_BONUS ;
166
170
}
167
171
}
168
172
TerminatorKind :: Call { func, unwind, .. } => {
0 commit comments