@@ -59,55 +59,52 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'a, 'tcx> {
59
59
let last_statement =
60
60
self . body . basic_blocks ( ) [ location. block ] . statements . last ( ) ?;
61
61
62
- match & last_statement. kind {
63
- StatementKind :: Assign ( box ( place, Rvalue :: Use ( op) ) ) => {
64
- let _const = op. constant ( ) ?;
65
- // We found a constant being assigned to `place`.
66
- // Now check that the target of this Goto switches on this place.
67
- let target_bb = & self . body . basic_blocks ( ) [ target] ;
68
- // FIXME(simonvandel): We are conservative here when we don't allow
69
- // any statements in the target basic block.
70
- // This could probably be relaxed to allow `StorageDead`s which could be
71
- // copied to the predecessor of this block.
72
- if !target_bb. statements . is_empty ( ) {
73
- None ?
74
- }
62
+ if let Some ( box ( place, Rvalue :: Use ( op) ) ) = last_statement. kind . as_assign ( ) {
63
+ let _const = op. constant ( ) ?;
64
+ // We found a constant being assigned to `place`.
65
+ // Now check that the target of this Goto switches on this place.
66
+ let target_bb = & self . body . basic_blocks ( ) [ target] ;
67
+ // FIXME(simonvandel): We are conservative here when we don't allow
68
+ // any statements in the target basic block.
69
+ // This could probably be relaxed to allow `StorageDead`s which could be
70
+ // copied to the predecessor of this block.
71
+ if !target_bb. statements . is_empty ( ) {
72
+ None ?
73
+ }
75
74
76
- let target_bb_terminator = target_bb. terminator ( ) ;
77
- match & target_bb_terminator. kind {
78
- TerminatorKind :: SwitchInt { discr, switch_ty, targets }
79
- if discr. place ( ) == Some ( * place) =>
80
- {
81
- // We now know that the Switch matches on the const place, and it is statementless
82
- // Now find which value in the Switch matches the const value.
83
- let const_value = _const. literal . try_eval_bits (
84
- self . tcx ,
85
- self . param_env ,
86
- switch_ty,
87
- ) ?;
88
- let found_value_idx_option = targets
89
- . iter ( )
90
- . enumerate ( )
91
- . find ( |( _, x) | const_value == x. 0 )
92
- . map ( |( idx, _) | idx) ;
75
+ 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) ;
93
92
94
- let target_to_use_in_goto =
95
- if let Some ( found_value_idx) = found_value_idx_option {
96
- targets. iter ( ) . nth ( found_value_idx) . unwrap ( ) . 1
97
- } else {
98
- // If we did not find the const value in values, it must be the otherwise case
99
- targets. otherwise ( )
100
- } ;
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
+ } ;
101
100
102
- self . optimizations . push ( OptimizationToApply {
103
- bb_with_goto : location. block ,
104
- target_to_use_in_goto,
105
- } ) ;
106
- }
107
- _ => { }
101
+ self . optimizations . push ( OptimizationToApply {
102
+ bb_with_goto : location. block ,
103
+ target_to_use_in_goto,
104
+ } ) ;
108
105
}
106
+ _ => { }
109
107
}
110
- _ => { }
111
108
}
112
109
}
113
110
_ => { }
0 commit comments