@@ -806,6 +806,35 @@ impl<'a> Parser<'a> {
806
806
}
807
807
true
808
808
} ) ;
809
+
810
+ struct IdentFinder {
811
+ idents : Vec < Ident > ,
812
+ /// If a block references one of the bindings introduced by the let pattern,
813
+ /// we likely meant to use `if let`.
814
+ /// This is pre-expansion, so if we encounter
815
+ /// `let Some(x) = foo() { println!("{x}") }` we won't find it.
816
+ references_ident : bool = false,
817
+ /// If a block has a `return`, then we know with high certainty that it was
818
+ /// meant to be let-else.
819
+ has_return : bool = false,
820
+ }
821
+
822
+ impl < ' a > Visitor < ' a > for IdentFinder {
823
+ fn visit_ident ( & mut self , ident : & Ident ) {
824
+ for i in & self . idents {
825
+ if ident. name == i. name {
826
+ self . references_ident = true ;
827
+ }
828
+ }
829
+ }
830
+ fn visit_expr ( & mut self , node : & ' a Expr ) {
831
+ if let ExprKind :: Ret ( ..) = node. kind {
832
+ self . has_return = true ;
833
+ }
834
+ walk_expr ( self , node) ;
835
+ }
836
+ }
837
+
809
838
// Collect all bindings in pattern and see if they appear in the block. Likely meant
810
839
// to write `if let`. See if the block has a return. Likely meant to write
811
840
// `let else`.
@@ -1132,30 +1161,3 @@ impl<'a> Parser<'a> {
1132
1161
self . mk_block ( thin_vec ! [ self . mk_stmt_err( span, guar) ] , BlockCheckMode :: Default , span)
1133
1162
}
1134
1163
}
1135
-
1136
- struct IdentFinder {
1137
- idents : Vec < Ident > ,
1138
- /// If a block references one of the bindings introduced by the let pattern, we likely meant to
1139
- /// use `if let`.
1140
- /// This is pre-expansion, so if we encounter `let Some(x) = foo() { println!("{x}") }` we won't
1141
- /// find it.
1142
- references_ident : bool = false,
1143
- /// If a block has a `return`, then we know with high certainty that the
1144
- has_return : bool = false,
1145
- }
1146
-
1147
- impl < ' a > Visitor < ' a > for IdentFinder {
1148
- fn visit_ident ( & mut self , ident : & Ident ) {
1149
- for i in & self . idents {
1150
- if ident. name == i. name {
1151
- self . references_ident = true ;
1152
- }
1153
- }
1154
- }
1155
- fn visit_expr ( & mut self , node : & ' a Expr ) {
1156
- if let ExprKind :: Ret ( ..) = node. kind {
1157
- self . has_return = true ;
1158
- }
1159
- walk_expr ( self , node) ;
1160
- }
1161
- }
0 commit comments