diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index b30cdb6ed..fb2a2fb28 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -15,7 +15,7 @@ use itertools::Itertools; | |||
15 | use rustc_hash::FxHashSet; | 15 | use rustc_hash::FxHashSet; |
16 | use syntax::{ | 16 | use syntax::{ |
17 | ast::{self, AstNode}, | 17 | ast::{self, AstNode}, |
18 | SyntaxNode, TextRange, T, | 18 | match_ast, SyntaxNode, TextRange, T, |
19 | }; | 19 | }; |
20 | use text_edit::TextEdit; | 20 | use text_edit::TextEdit; |
21 | 21 | ||
@@ -80,7 +80,7 @@ pub(crate) fn diagnostics( | |||
80 | 80 | ||
81 | for node in parse.tree().syntax().descendants() { | 81 | for node in parse.tree().syntax().descendants() { |
82 | check_unnecessary_braces_in_use_statement(&mut res, file_id, &node); | 82 | check_unnecessary_braces_in_use_statement(&mut res, file_id, &node); |
83 | check_struct_shorthand_initialization(&mut res, file_id, &node); | 83 | check_field_shorthand(&mut res, file_id, &node); |
84 | } | 84 | } |
85 | let res = RefCell::new(res); | 85 | let res = RefCell::new(res); |
86 | let sink_builder = DiagnosticSinkBuilder::new() | 86 | let sink_builder = DiagnosticSinkBuilder::new() |
@@ -188,12 +188,20 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( | |||
188 | None | 188 | None |
189 | } | 189 | } |
190 | 190 | ||
191 | fn check_struct_shorthand_initialization( | 191 | fn check_field_shorthand(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) { |
192 | match_ast! { | ||
193 | match node { | ||
194 | ast::RecordExpr(it) => check_expr_field_shorthand(acc, file_id, it), | ||
195 | _ => None | ||
196 | } | ||
197 | }; | ||
198 | } | ||
199 | |||
200 | fn check_expr_field_shorthand( | ||
192 | acc: &mut Vec<Diagnostic>, | 201 | acc: &mut Vec<Diagnostic>, |
193 | file_id: FileId, | 202 | file_id: FileId, |
194 | node: &SyntaxNode, | 203 | record_lit: ast::RecordExpr, |
195 | ) -> Option<()> { | 204 | ) -> Option<()> { |
196 | let record_lit = ast::RecordExpr::cast(node.clone())?; | ||
197 | let record_field_list = record_lit.record_expr_field_list()?; | 205 | let record_field_list = record_lit.record_expr_field_list()?; |
198 | for record_field in record_field_list.fields() { | 206 | for record_field in record_field_list.fields() { |
199 | if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) { | 207 | if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) { |