@@ -263,21 +263,26 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
263
263
Some ( parent) => parent,
264
264
None => continue ,
265
265
} ;
266
+ let name_ast = match ident_pat. name ( ) {
267
+ Some ( name_ast) => name_ast,
268
+ None => continue ,
269
+ } ;
266
270
267
- // We have to check that it's either `let var = ...` or `Variant(_) @ var ` statement,
271
+ // We have to check that it's either `let var = ...` or `var @ Variant(_)` statement,
268
272
// because e.g. match arms are patterns as well.
269
273
// In other words, we check that it's a named variable binding.
270
- if !ast:: LetStmt :: cast ( parent. clone ( ) ) . is_some ( )
271
- && !ast:: IdentPat :: cast ( parent) . is_some ( )
272
- {
274
+ let is_binding = ast:: LetStmt :: cast ( parent. clone ( ) ) . is_some ( )
275
+ || ( ast:: MatchArm :: cast ( parent) . is_some ( )
276
+ && ident_pat. at_token ( ) . is_some ( ) ) ;
277
+ if !is_binding {
273
278
// This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm.
274
279
continue ;
275
280
}
276
281
277
282
let diagnostic = IncorrectCase {
278
283
file : source_ptr. file_id ,
279
284
ident_type : "Variable" . to_string ( ) ,
280
- ident : AstPtr :: new ( & ident_pat ) . into ( ) ,
285
+ ident : AstPtr :: new ( & name_ast ) . into ( ) ,
281
286
expected_case : replacement. expected_case ,
282
287
ident_text : replacement. current_name . to_string ( ) ,
283
288
suggested_text : replacement. suggested_text ,
@@ -801,8 +806,8 @@ enum Option { Some, None }
801
806
802
807
fn main() {
803
808
match Option::None {
804
- None @ SOME_VAR => (),
805
- // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var`
809
+ SOME_VAR @ None => (),
810
+ // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var`
806
811
Some => (),
807
812
}
808
813
}
0 commit comments