@@ -52,21 +52,20 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
52
52
53
53
impl < ' a , ' tcx > Visitor < ' tcx > for ConstGotoOptimizationFinder < ' a , ' tcx > {
54
54
fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , location : Location ) {
55
- let _: Option < _ > = try {
55
+ let _: Option < _ > = try {
56
56
let target = terminator. kind . as_goto ( ) ?;
57
57
// We only apply this optimization if the last statement is a const assignment
58
- let last_statement =
59
- self . body . basic_blocks ( ) [ location. block ] . statements . last ( ) ?;
58
+ let last_statement = self . body . basic_blocks ( ) [ location. block ] . statements . last ( ) ?;
60
59
61
- if let Some ( box ( place, Rvalue :: Use ( op) ) ) = last_statement. kind . as_assign ( ) {
60
+ if let Some ( box ( place, Rvalue :: Use ( op) ) ) = last_statement. kind . as_assign ( ) {
62
61
let _const = op. constant ( ) ?;
63
62
// We found a constant being assigned to `place`.
64
63
// Now check that the target of this Goto switches on this place.
65
64
let target_bb = & self . body . basic_blocks ( ) [ target] ;
66
-
67
- // FIXME(simonvandel): We are conservative here when we don't allow
65
+
66
+ // FIXME(simonvandel): We are conservative here when we don't allow
68
67
// any statements in the target basic block.
69
- // This could probably be relaxed to allow `StorageDead`s which could be
68
+ // This could probably be relaxed to allow `StorageDead`s which could be
70
69
// copied to the predecessor of this block.
71
70
if !target_bb. statements . is_empty ( ) {
72
71
None ?
@@ -77,15 +76,12 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'a, 'tcx> {
77
76
if discr. place ( ) == Some ( * place) {
78
77
// We now know that the Switch matches on the const place, and it is statementless
79
78
// 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
- ) ?;
79
+ let const_value =
80
+ _const. literal . try_eval_bits ( self . tcx , self . param_env , switch_ty) ?;
85
81
let found_value_idx_option = targets
86
82
. iter ( )
87
83
. enumerate ( )
88
- . find ( |( _, ( value, _) ) | const_value == * value)
84
+ . find ( |( _, ( value, _) ) | const_value == * value)
89
85
. map ( |( idx, _) | idx) ;
90
86
91
87
let target_to_use_in_goto =
0 commit comments