@@ -88,9 +88,9 @@ pub use crate::{
88
88
diagnostics:: {
89
89
AnyDiagnostic , BreakOutsideOfLoop , InactiveCode , InternalBailedOut , MacroError ,
90
90
MismatchedArgCount , MissingFields , MissingMatchArms , MissingOkOrSomeInTailExpr ,
91
- MissingPatFields , MissingUnsafe , NoSuchField , RemoveThisSemicolon ,
92
- ReplaceFilterMapNextWithFindMap , UnimplementedBuiltinMacro , UnresolvedExternCrate ,
93
- UnresolvedImport , UnresolvedMacroCall , UnresolvedModule , UnresolvedProcMacro ,
91
+ MissingUnsafe , NoSuchField , RemoveThisSemicolon , ReplaceFilterMapNextWithFindMap ,
92
+ UnimplementedBuiltinMacro , UnresolvedExternCrate , UnresolvedImport , UnresolvedMacroCall ,
93
+ UnresolvedModule , UnresolvedProcMacro ,
94
94
} ,
95
95
has_source:: HasSource ,
96
96
semantics:: { PathResolution , Semantics , SemanticsScope } ,
@@ -609,23 +609,21 @@ impl Module {
609
609
}
610
610
for decl in self . declarations ( db) {
611
611
match decl {
612
- crate :: ModuleDef :: Function ( f) => f. diagnostics ( db, sink, internal_diagnostics) ,
613
- crate :: ModuleDef :: Module ( m) => {
612
+ ModuleDef :: Function ( f) => acc . extend ( f. diagnostics ( db, sink, internal_diagnostics) ) ,
613
+ ModuleDef :: Module ( m) => {
614
614
// Only add diagnostics from inline modules
615
615
if def_map[ m. id . local_id ] . origin . is_inline ( ) {
616
616
acc. extend ( m. diagnostics ( db, sink, internal_diagnostics) )
617
617
}
618
618
}
619
- _ => {
620
- decl. diagnostics ( db, sink) ;
621
- }
619
+ _ => decl. diagnostics ( db, sink) ,
622
620
}
623
621
}
624
622
625
623
for impl_def in self . impl_defs ( db) {
626
624
for item in impl_def. items ( db) {
627
625
if let AssocItem :: Function ( f) = item {
628
- f. diagnostics ( db, sink, internal_diagnostics) ;
626
+ acc . extend ( f. diagnostics ( db, sink, internal_diagnostics) ) ;
629
627
}
630
628
}
631
629
}
@@ -1033,7 +1031,8 @@ impl Function {
1033
1031
db : & dyn HirDatabase ,
1034
1032
sink : & mut DiagnosticSink ,
1035
1033
internal_diagnostics : bool ,
1036
- ) {
1034
+ ) -> Vec < AnyDiagnostic > {
1035
+ let mut acc: Vec < AnyDiagnostic > = Vec :: new ( ) ;
1037
1036
let krate = self . module ( db) . id . krate ( ) ;
1038
1037
1039
1038
let source_map = db. body_with_source_map ( self . id . into ( ) ) . 1 ;
@@ -1099,64 +1098,70 @@ impl Function {
1099
1098
BodyValidationDiagnostic :: collect ( db, self . id . into ( ) , internal_diagnostics)
1100
1099
{
1101
1100
match diagnostic {
1102
- BodyValidationDiagnostic :: RecordLiteralMissingFields {
1103
- record_expr ,
1101
+ BodyValidationDiagnostic :: RecordMissingFields {
1102
+ record ,
1104
1103
variant,
1105
1104
missed_fields,
1106
- } => match source_map. expr_syntax ( record_expr) {
1107
- Ok ( source_ptr) => {
1108
- let root = source_ptr. file_syntax ( db. upcast ( ) ) ;
1109
- if let ast:: Expr :: RecordExpr ( record_expr) = & source_ptr. value . to_node ( & root)
1110
- {
1111
- if let Some ( _) = record_expr. record_expr_field_list ( ) {
1112
- let variant_data = variant. variant_data ( db. upcast ( ) ) ;
1113
- let missed_fields = missed_fields
1114
- . into_iter ( )
1115
- . map ( |idx| variant_data. fields ( ) [ idx] . name . clone ( ) )
1116
- . collect ( ) ;
1117
- sink. push ( MissingFields {
1118
- file : source_ptr. file_id ,
1119
- field_list_parent : AstPtr :: new ( record_expr) ,
1120
- field_list_parent_path : record_expr
1121
- . path ( )
1122
- . map ( |path| AstPtr :: new ( & path) ) ,
1123
- missed_fields,
1124
- } )
1105
+ } => {
1106
+ let variant_data = variant. variant_data ( db. upcast ( ) ) ;
1107
+ let missed_fields = missed_fields
1108
+ . into_iter ( )
1109
+ . map ( |idx| variant_data. fields ( ) [ idx] . name . clone ( ) )
1110
+ . collect ( ) ;
1111
+
1112
+ match record {
1113
+ Either :: Left ( record_expr) => match source_map. expr_syntax ( record_expr) {
1114
+ Ok ( source_ptr) => {
1115
+ let root = source_ptr. file_syntax ( db. upcast ( ) ) ;
1116
+ if let ast:: Expr :: RecordExpr ( record_expr) =
1117
+ & source_ptr. value . to_node ( & root)
1118
+ {
1119
+ if let Some ( _) = record_expr. record_expr_field_list ( ) {
1120
+ acc. push (
1121
+ MissingFields {
1122
+ file : source_ptr. file_id ,
1123
+ field_list_parent : Either :: Left ( AstPtr :: new (
1124
+ record_expr,
1125
+ ) ) ,
1126
+ field_list_parent_path : record_expr
1127
+ . path ( )
1128
+ . map ( |path| AstPtr :: new ( & path) ) ,
1129
+ missed_fields,
1130
+ }
1131
+ . into ( ) ,
1132
+ )
1133
+ }
1134
+ }
1125
1135
}
1126
- }
1127
- }
1128
- Err ( SyntheticSyntax ) => ( ) ,
1129
- } ,
1130
- BodyValidationDiagnostic :: RecordPatMissingFields {
1131
- record_pat,
1132
- variant,
1133
- missed_fields,
1134
- } => match source_map. pat_syntax ( record_pat) {
1135
- Ok ( source_ptr) => {
1136
- if let Some ( expr) = source_ptr. value . as_ref ( ) . left ( ) {
1137
- let root = source_ptr. file_syntax ( db. upcast ( ) ) ;
1138
- if let ast:: Pat :: RecordPat ( record_pat) = expr. to_node ( & root) {
1139
- if let Some ( _) = record_pat. record_pat_field_list ( ) {
1140
- let variant_data = variant. variant_data ( db. upcast ( ) ) ;
1141
- let missed_fields = missed_fields
1142
- . into_iter ( )
1143
- . map ( |idx| variant_data. fields ( ) [ idx] . name . clone ( ) )
1144
- . collect ( ) ;
1145
- sink. push ( MissingPatFields {
1146
- file : source_ptr. file_id ,
1147
- field_list_parent : AstPtr :: new ( & record_pat) ,
1148
- field_list_parent_path : record_pat
1149
- . path ( )
1150
- . map ( |path| AstPtr :: new ( & path) ) ,
1151
- missed_fields,
1152
- } )
1136
+ Err ( SyntheticSyntax ) => ( ) ,
1137
+ } ,
1138
+ Either :: Right ( record_pat) => match source_map. pat_syntax ( record_pat) {
1139
+ Ok ( source_ptr) => {
1140
+ if let Some ( expr) = source_ptr. value . as_ref ( ) . left ( ) {
1141
+ let root = source_ptr. file_syntax ( db. upcast ( ) ) ;
1142
+ if let ast:: Pat :: RecordPat ( record_pat) = expr. to_node ( & root) {
1143
+ if let Some ( _) = record_pat. record_pat_field_list ( ) {
1144
+ acc. push (
1145
+ MissingFields {
1146
+ file : source_ptr. file_id ,
1147
+ field_list_parent : Either :: Right ( AstPtr :: new (
1148
+ & record_pat,
1149
+ ) ) ,
1150
+ field_list_parent_path : record_pat
1151
+ . path ( )
1152
+ . map ( |path| AstPtr :: new ( & path) ) ,
1153
+ missed_fields,
1154
+ }
1155
+ . into ( ) ,
1156
+ )
1157
+ }
1158
+ }
1153
1159
}
1154
1160
}
1155
- }
1161
+ Err ( SyntheticSyntax ) => ( ) ,
1162
+ } ,
1156
1163
}
1157
- Err ( SyntheticSyntax ) => ( ) ,
1158
- } ,
1159
-
1164
+ }
1160
1165
BodyValidationDiagnostic :: ReplaceFilterMapNextWithFindMap { method_call_expr } => {
1161
1166
if let Ok ( next_source_ptr) = source_map. expr_syntax ( method_call_expr) {
1162
1167
sink. push ( ReplaceFilterMapNextWithFindMap {
@@ -1234,6 +1239,7 @@ impl Function {
1234
1239
for diag in hir_ty:: diagnostics:: validate_module_item ( db, krate, self . id . into ( ) ) {
1235
1240
sink. push ( diag)
1236
1241
}
1242
+ acc
1237
1243
}
1238
1244
1239
1245
/// Whether this function declaration has a definition.
0 commit comments