File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -187,7 +187,12 @@ fn check_struct_shorthand_initialization(
187
187
if let ( Some ( name_ref) , Some ( expr) ) = ( record_field. name_ref ( ) , record_field. expr ( ) ) {
188
188
let field_name = name_ref. syntax ( ) . text ( ) . to_string ( ) ;
189
189
let field_expr = expr. syntax ( ) . text ( ) . to_string ( ) ;
190
- if field_name == field_expr {
190
+ let field_name_is_tup_index = name_ref
191
+ . syntax ( )
192
+ . first_token ( )
193
+ . map ( |token| token. kind ( ) . is_literal ( ) )
194
+ . unwrap_or ( false ) ;
195
+ if field_name == field_expr && !field_name_is_tup_index {
191
196
let mut edit_builder = TextEditBuilder :: default ( ) ;
192
197
edit_builder. delete ( record_field. syntax ( ) . text_range ( ) ) ;
193
198
edit_builder. insert ( record_field. syntax ( ) . text_range ( ) . start ( ) , field_name) ;
@@ -719,6 +724,18 @@ mod tests {
719
724
"# ,
720
725
check_struct_shorthand_initialization,
721
726
) ;
727
+ check_not_applicable (
728
+ r#"
729
+ struct A(usize);
730
+
731
+ fn main() {
732
+ A {
733
+ 0: 0
734
+ }
735
+ }
736
+ "# ,
737
+ check_struct_shorthand_initialization,
738
+ ) ;
722
739
723
740
check_apply (
724
741
r#"
You can’t perform that action at this time.
0 commit comments