@@ -15,7 +15,7 @@ use itertools::Itertools;
1515use rustc_hash:: FxHashSet ;
1616use syntax:: {
1717 ast:: { self , AstNode } ,
18- SyntaxNode , TextRange , T ,
18+ match_ast , SyntaxNode , TextRange , T ,
1919} ;
2020use text_edit:: TextEdit ;
2121
@@ -80,7 +80,7 @@ pub(crate) fn diagnostics(
8080
8181 for node in parse. tree ( ) . syntax ( ) . descendants ( ) {
8282 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) ;
8484 }
8585 let res = RefCell :: new ( res) ;
8686 let sink_builder = DiagnosticSinkBuilder :: new ( )
@@ -188,12 +188,20 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
188188 None
189189}
190190
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 (
192201 acc : & mut Vec < Diagnostic > ,
193202 file_id : FileId ,
194- node : & SyntaxNode ,
203+ record_lit : ast :: RecordExpr ,
195204) -> Option < ( ) > {
196- let record_lit = ast:: RecordExpr :: cast ( node. clone ( ) ) ?;
197205 let record_field_list = record_lit. record_expr_field_list ( ) ?;
198206 for record_field in record_field_list. fields ( ) {
199207 if let ( Some ( name_ref) , Some ( expr) ) = ( record_field. name_ref ( ) , record_field. expr ( ) ) {
0 commit comments