@@ -201,35 +201,42 @@ fn check_expr_field_shorthand(
201
201
acc : & mut Vec < Diagnostic > ,
202
202
file_id : FileId ,
203
203
record_lit : ast:: RecordExpr ,
204
- ) -> Option < ( ) > {
205
- let record_field_list = record_lit. record_expr_field_list ( ) ?;
204
+ ) {
205
+ let record_field_list = match record_lit. record_expr_field_list ( ) {
206
+ Some ( it) => it,
207
+ None => ( ) ,
208
+ } ;
206
209
for record_field in record_field_list. fields ( ) {
207
- if let ( Some ( name_ref) , Some ( expr) ) = ( record_field. name_ref ( ) , record_field. expr ( ) ) {
208
- let field_name = name_ref. syntax ( ) . text ( ) . to_string ( ) ;
209
- let field_expr = expr. syntax ( ) . text ( ) . to_string ( ) ;
210
- let field_name_is_tup_index = name_ref. as_tuple_field ( ) . is_some ( ) ;
211
- if field_name == field_expr && !field_name_is_tup_index {
212
- let mut edit_builder = TextEdit :: builder ( ) ;
213
- edit_builder. delete ( record_field. syntax ( ) . text_range ( ) ) ;
214
- edit_builder. insert ( record_field. syntax ( ) . text_range ( ) . start ( ) , field_name) ;
215
- let edit = edit_builder. finish ( ) ;
216
-
217
- let field_range = record_field. syntax ( ) . text_range ( ) ;
218
- acc. push ( Diagnostic {
219
- // name: None,
220
- range : field_range,
221
- message : "Shorthand struct initialization" . to_string ( ) ,
222
- severity : Severity :: WeakWarning ,
223
- fix : Some ( Fix :: new (
224
- "Use struct shorthand initialization" ,
225
- SourceFileEdit { file_id, edit } . into ( ) ,
226
- field_range,
227
- ) ) ,
228
- } ) ;
229
- }
210
+ let ( name_ref, expr) = match record_field. name_ref ( ) . zip ( record_field. expr ( ) ) {
211
+ Some ( it) => it,
212
+ None => continue ,
213
+ } ;
214
+
215
+ let field_name = name_ref. syntax ( ) . text ( ) . to_string ( ) ;
216
+ let field_expr = expr. syntax ( ) . text ( ) . to_string ( ) ;
217
+ let field_name_is_tup_index = name_ref. as_tuple_field ( ) . is_some ( ) ;
218
+ if field_name != field_expr || field_name_is_tup_index {
219
+ continue ;
230
220
}
221
+
222
+ let mut edit_builder = TextEdit :: builder ( ) ;
223
+ edit_builder. delete ( record_field. syntax ( ) . text_range ( ) ) ;
224
+ edit_builder. insert ( record_field. syntax ( ) . text_range ( ) . start ( ) , field_name) ;
225
+ let edit = edit_builder. finish ( ) ;
226
+
227
+ let field_range = record_field. syntax ( ) . text_range ( ) ;
228
+ acc. push ( Diagnostic {
229
+ // name: None,
230
+ range : field_range,
231
+ message : "Shorthand struct initialization" . to_string ( ) ,
232
+ severity : Severity :: WeakWarning ,
233
+ fix : Some ( Fix :: new (
234
+ "Use struct shorthand initialization" ,
235
+ SourceFileEdit { file_id, edit } . into ( ) ,
236
+ field_range,
237
+ ) ) ,
238
+ } ) ;
231
239
}
232
- Some ( ( ) )
233
240
}
234
241
235
242
#[ cfg( test) ]
0 commit comments