@@ -193,8 +193,20 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
193193 let eq_bb = patch. new_block ( eq_switch) ;
194194
195195 // Jump to it on the basis of the inequality comparison
196- let true_case = opt_data. destination ;
197- let false_case = eq_bb;
196+ let mut true_case = opt_data. destination ;
197+ let mut false_case = eq_bb;
198+ // Create an indirect BB to add `StorageDead` If the jump target is itself.
199+ for bb in [ & mut false_case, & mut true_case] . into_iter ( ) {
200+ if * bb == parent {
201+ * bb = patch. new_block ( BasicBlockData :: new (
202+ Some ( Terminator {
203+ kind : TerminatorKind :: Goto { target : parent } ,
204+ source_info : bbs[ parent] . terminator ( ) . source_info ,
205+ } ) ,
206+ bbs[ parent] . is_cleanup ,
207+ ) ) ;
208+ }
209+ }
198210 patch. patch_terminator (
199211 parent,
200212 TerminatorKind :: if_ ( Operand :: Move ( Place :: from ( comp_temp) ) , true_case, false_case) ,
@@ -210,9 +222,9 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
210222
211223 // Generate a StorageDead for comp_temp in each of the targets, since we moved it into
212224 // the switch
213- for bb in [ false_case, true_case] . iter ( ) {
225+ for bb in [ false_case, true_case] . into_iter ( ) {
214226 patch. add_statement (
215- Location { block : * bb, statement_index : 0 } ,
227+ Location { block : bb, statement_index : 0 } ,
216228 StatementKind :: StorageDead ( comp_temp) ,
217229 ) ;
218230 }
0 commit comments