@@ -336,48 +336,44 @@ impl<'a> DeclValidator<'a> {
336
336
337
337
for ( id, replacement) in pats_replacements {
338
338
if let Ok ( source_ptr) = source_map. pat_syntax ( id) {
339
- if let Some ( expr ) = source_ptr. value . as_ref ( ) . left ( ) {
339
+ if let Some ( ptr ) = source_ptr. value . clone ( ) . cast :: < ast :: IdentPat > ( ) {
340
340
let root = source_ptr. file_syntax ( self . db . upcast ( ) ) ;
341
- if let ast:: Pat :: IdentPat ( ident_pat) = expr. to_node ( & root) {
342
- let parent = match ident_pat. syntax ( ) . parent ( ) {
343
- Some ( parent) => parent,
344
- None => continue ,
345
- } ;
346
- let name_ast = match ident_pat. name ( ) {
347
- Some ( name_ast) => name_ast,
348
- None => continue ,
349
- } ;
341
+ let ident_pat = ptr. to_node ( & root) ;
342
+ let parent = match ident_pat. syntax ( ) . parent ( ) {
343
+ Some ( parent) => parent,
344
+ None => continue ,
345
+ } ;
346
+ let name_ast = match ident_pat. name ( ) {
347
+ Some ( name_ast) => name_ast,
348
+ None => continue ,
349
+ } ;
350
+
351
+ let is_param = ast:: Param :: can_cast ( parent. kind ( ) ) ;
352
+
353
+ // We have to check that it's either `let var = ...` or `var @ Variant(_)` statement,
354
+ // because e.g. match arms are patterns as well.
355
+ // In other words, we check that it's a named variable binding.
356
+ let is_binding = ast:: LetStmt :: can_cast ( parent. kind ( ) )
357
+ || ( ast:: MatchArm :: can_cast ( parent. kind ( ) )
358
+ && ident_pat. at_token ( ) . is_some ( ) ) ;
359
+ if !( is_param || is_binding) {
360
+ // This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm.
361
+ continue ;
362
+ }
350
363
351
- let is_param = ast:: Param :: can_cast ( parent. kind ( ) ) ;
352
-
353
- // We have to check that it's either `let var = ...` or `var @ Variant(_)` statement,
354
- // because e.g. match arms are patterns as well.
355
- // In other words, we check that it's a named variable binding.
356
- let is_binding = ast:: LetStmt :: can_cast ( parent. kind ( ) )
357
- || ( ast:: MatchArm :: can_cast ( parent. kind ( ) )
358
- && ident_pat. at_token ( ) . is_some ( ) ) ;
359
- if !( is_param || is_binding) {
360
- // This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm.
361
- continue ;
362
- }
364
+ let ident_type =
365
+ if is_param { IdentType :: Parameter } else { IdentType :: Variable } ;
363
366
364
- let ident_type =
365
- if is_param { IdentType :: Parameter } else { IdentType :: Variable } ;
366
-
367
- let diagnostic = IncorrectCase {
368
- file : source_ptr. file_id ,
369
- ident_type,
370
- ident : AstPtr :: new ( & name_ast) ,
371
- expected_case : replacement. expected_case ,
372
- ident_text : replacement
373
- . current_name
374
- . display ( self . db . upcast ( ) )
375
- . to_string ( ) ,
376
- suggested_text : replacement. suggested_text ,
377
- } ;
367
+ let diagnostic = IncorrectCase {
368
+ file : source_ptr. file_id ,
369
+ ident_type,
370
+ ident : AstPtr :: new ( & name_ast) ,
371
+ expected_case : replacement. expected_case ,
372
+ ident_text : replacement. current_name . display ( self . db . upcast ( ) ) . to_string ( ) ,
373
+ suggested_text : replacement. suggested_text ,
374
+ } ;
378
375
379
- self . sink . push ( diagnostic) ;
380
- }
376
+ self . sink . push ( diagnostic) ;
381
377
}
382
378
}
383
379
}
0 commit comments