@@ -73,37 +73,33 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'a, 'tcx> {
7373 }
7474
7575 let target_bb_terminator = target_bb. terminator ( ) ;
76- match & target_bb_terminator. kind {
77- TerminatorKind :: SwitchInt { discr, switch_ty, targets }
78- if discr. place ( ) == Some ( * place) =>
79- {
80- // We now know that the Switch matches on the const place, and it is statementless
81- // Now find which value in the Switch matches the const value.
82- let const_value = _const. literal . try_eval_bits (
83- self . tcx ,
84- self . param_env ,
85- switch_ty,
86- ) ?;
87- let found_value_idx_option = targets
88- . iter ( )
89- . enumerate ( )
90- . find ( |( _, x) | const_value == x. 0 )
91- . map ( |( idx, _) | idx) ;
76+ let ( discr, switch_ty, targets) = target_bb_terminator. kind . as_switch ( ) ?;
77+ if discr. place ( ) == Some ( * place) {
78+ // We now know that the Switch matches on the const place, and it is statementless
79+ // Now find which value in the Switch matches the const value.
80+ let const_value = _const. literal . try_eval_bits (
81+ self . tcx ,
82+ self . param_env ,
83+ switch_ty,
84+ ) ?;
85+ let found_value_idx_option = targets
86+ . iter ( )
87+ . enumerate ( )
88+ . find ( |( _, x) | const_value == x. 0 )
89+ . map ( |( idx, _) | idx) ;
9290
93- let target_to_use_in_goto =
94- if let Some ( found_value_idx) = found_value_idx_option {
95- targets. iter ( ) . nth ( found_value_idx) . unwrap ( ) . 1
96- } else {
97- // If we did not find the const value in values, it must be the otherwise case
98- targets. otherwise ( )
99- } ;
91+ let target_to_use_in_goto =
92+ if let Some ( found_value_idx) = found_value_idx_option {
93+ targets. iter ( ) . nth ( found_value_idx) . unwrap ( ) . 1
94+ } else {
95+ // If we did not find the const value in values, it must be the otherwise case
96+ targets. otherwise ( )
97+ } ;
10098
101- self . optimizations . push ( OptimizationToApply {
102- bb_with_goto : location. block ,
103- target_to_use_in_goto,
104- } ) ;
105- }
106- _ => { }
99+ self . optimizations . push ( OptimizationToApply {
100+ bb_with_goto : location. block ,
101+ target_to_use_in_goto,
102+ } ) ;
107103 }
108104 }
109105 }
0 commit comments