@@ -15,7 +15,7 @@ use itertools::Itertools;
15
15
use rustc_hash:: FxHashSet ;
16
16
use syntax:: {
17
17
ast:: { self , AstNode } ,
18
- SyntaxNode , TextRange , T ,
18
+ match_ast , SyntaxNode , TextRange , T ,
19
19
} ;
20
20
use text_edit:: TextEdit ;
21
21
@@ -80,7 +80,7 @@ pub(crate) fn diagnostics(
80
80
81
81
for node in parse. tree ( ) . syntax ( ) . descendants ( ) {
82
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
85
let res = RefCell :: new ( res) ;
86
86
let sink_builder = DiagnosticSinkBuilder :: new ( )
@@ -188,12 +188,20 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
188
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
201
acc : & mut Vec < Diagnostic > ,
193
202
file_id : FileId ,
194
- node : & SyntaxNode ,
203
+ record_lit : ast :: RecordExpr ,
195
204
) -> Option < ( ) > {
196
- let record_lit = ast:: RecordExpr :: cast ( node. clone ( ) ) ?;
197
205
let record_field_list = record_lit. record_expr_field_list ( ) ?;
198
206
for record_field in record_field_list. fields ( ) {
199
207
if let ( Some ( name_ref) , Some ( expr) ) = ( record_field. name_ref ( ) , record_field. expr ( ) ) {
0 commit comments