@@ -152,7 +152,12 @@ fn add_field_to_struct_fix(
152
152
} else {
153
153
Some ( make:: visibility_pub_crate ( ) )
154
154
} ;
155
- let field_name = make:: name ( field_name) ;
155
+
156
+ let field_name = match field_name. chars ( ) . next ( ) {
157
+ Some ( ch) if ch. is_numeric ( ) => return None ,
158
+ Some ( _) => make:: name ( field_name) ,
159
+ None => return None ,
160
+ } ;
156
161
157
162
let ( offset, record_field) = record_field_layout (
158
163
visibility,
@@ -178,7 +183,12 @@ fn add_field_to_struct_fix(
178
183
None => {
179
184
// Add a field list to the Unit Struct
180
185
let mut src_change_builder = SourceChangeBuilder :: new ( struct_range. file_id ) ;
181
- let field_name = make:: name ( field_name) ;
186
+ let field_name = match field_name. chars ( ) . next ( ) {
187
+ // FIXME : See match arm below regarding tuple structs.
188
+ Some ( ch) if ch. is_numeric ( ) => return None ,
189
+ Some ( _) => make:: name ( field_name) ,
190
+ None => return None ,
191
+ } ;
182
192
let visibility = if error_range. file_id == struct_range. file_id {
183
193
None
184
194
} else {
@@ -274,7 +284,7 @@ mod tests {
274
284
use crate :: {
275
285
tests:: {
276
286
check_diagnostics, check_diagnostics_with_config, check_diagnostics_with_disabled,
277
- check_fix,
287
+ check_fix, check_no_fix ,
278
288
} ,
279
289
DiagnosticsConfig ,
280
290
} ;
@@ -459,4 +469,36 @@ fn foo() {
459
469
"# ,
460
470
) ;
461
471
}
472
+
473
+ #[ test]
474
+ fn no_fix_when_indexed ( ) {
475
+ check_no_fix (
476
+ r#"
477
+ struct Kek {}
478
+ impl Kek {
479
+ pub fn foo(self) {
480
+ self.$00
481
+ }
482
+ }
483
+
484
+ fn main() {}
485
+ "# ,
486
+ )
487
+ }
488
+
489
+ #[ test]
490
+ fn no_fix_when_without_field ( ) {
491
+ check_no_fix (
492
+ r#"
493
+ struct Kek {}
494
+ impl Kek {
495
+ pub fn foo(self) {
496
+ self.$0
497
+ }
498
+ }
499
+
500
+ fn main() {}
501
+ "# ,
502
+ )
503
+ }
462
504
}
0 commit comments