@@ -64,22 +64,36 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
64
64
} )
65
65
} )
66
66
. on :: < hir:: diagnostics:: MissingFields , _ > ( |d| {
67
- let mut field_list = d. ast ( db) ;
68
- for f in d. missed_fields . iter ( ) {
69
- let field = make:: record_field ( make:: name_ref ( & f. to_string ( ) ) , Some ( make:: expr_unit ( ) ) ) ;
70
- field_list = field_list. append_field ( & field) ;
71
- }
72
-
73
- let mut builder = TextEditBuilder :: default ( ) ;
74
- algo:: diff ( & d. ast ( db) . syntax ( ) , & field_list. syntax ( ) ) . into_text_edit ( & mut builder) ;
67
+ // Note that although we could add a diagnostics to
68
+ // fill the missing tuple field, e.g :
69
+ // `struct A(usize);`
70
+ // `let a = A { 0: () }`
71
+ // but it is uncommon usage and it should not be encouraged.
72
+ let fix = if d. missed_fields . iter ( ) . any ( |it| it. as_tuple_index ( ) . is_some ( ) ) {
73
+ None
74
+ } else {
75
+ let mut field_list = d. ast ( db) ;
76
+ for f in d. missed_fields . iter ( ) {
77
+ let field =
78
+ make:: record_field ( make:: name_ref ( & f. to_string ( ) ) , Some ( make:: expr_unit ( ) ) ) ;
79
+ field_list = field_list. append_field ( & field) ;
80
+ }
81
+
82
+ let mut builder = TextEditBuilder :: default ( ) ;
83
+ algo:: diff ( & d. ast ( db) . syntax ( ) , & field_list. syntax ( ) ) . into_text_edit ( & mut builder) ;
84
+
85
+ Some ( SourceChange :: source_file_edit_from (
86
+ "fill struct fields" ,
87
+ file_id,
88
+ builder. finish ( ) ,
89
+ ) )
90
+ } ;
75
91
76
- let fix =
77
- SourceChange :: source_file_edit_from ( "fill struct fields" , file_id, builder. finish ( ) ) ;
78
92
res. borrow_mut ( ) . push ( Diagnostic {
79
93
range : d. highlight_range ( ) ,
80
94
message : d. message ( ) ,
81
95
severity : Severity :: Error ,
82
- fix : Some ( fix ) ,
96
+ fix,
83
97
} )
84
98
} )
85
99
. on :: < hir:: diagnostics:: MissingOkInTailExpr , _ > ( |d| {
0 commit comments