diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/diagnostics/decl_check.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index 3a95f1b82..28ce15773 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs | |||
@@ -263,13 +263,18 @@ impl<'a, 'b> DeclValidator<'a, 'b> { | |||
263 | Some(parent) => parent, | 263 | Some(parent) => parent, |
264 | None => continue, | 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 | // because e.g. match arms are patterns as well. | 272 | // because e.g. match arms are patterns as well. |
269 | // In other words, we check that it's a named variable binding. | 273 | // In other words, we check that it's a named variable binding. |
270 | if !ast::LetStmt::cast(parent.clone()).is_some() | 274 | let is_binding = ast::LetStmt::cast(parent.clone()).is_some() |
271 | && !ast::IdentPat::cast(parent).is_some() | 275 | || (ast::MatchArm::cast(parent).is_some() |
272 | { | 276 | && ident_pat.at_token().is_some()); |
277 | if !is_binding { | ||
273 | // This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm. | 278 | // This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm. |
274 | continue; | 279 | continue; |
275 | } | 280 | } |
@@ -277,7 +282,7 @@ impl<'a, 'b> DeclValidator<'a, 'b> { | |||
277 | let diagnostic = IncorrectCase { | 282 | let diagnostic = IncorrectCase { |
278 | file: source_ptr.file_id, | 283 | file: source_ptr.file_id, |
279 | ident_type: "Variable".to_string(), | 284 | ident_type: "Variable".to_string(), |
280 | ident: AstPtr::new(&ident_pat).into(), | 285 | ident: AstPtr::new(&name_ast).into(), |
281 | expected_case: replacement.expected_case, | 286 | expected_case: replacement.expected_case, |
282 | ident_text: replacement.current_name.to_string(), | 287 | ident_text: replacement.current_name.to_string(), |
283 | suggested_text: replacement.suggested_text, | 288 | suggested_text: replacement.suggested_text, |
@@ -801,8 +806,8 @@ enum Option { Some, None } | |||
801 | 806 | ||
802 | fn main() { | 807 | fn main() { |
803 | match Option::None { | 808 | match Option::None { |
804 | None @ SOME_VAR => (), | 809 | SOME_VAR @ None => (), |
805 | // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var` | 810 | // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var` |
806 | Some => (), | 811 | Some => (), |
807 | } | 812 | } |
808 | } | 813 | } |