aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-13 13:49:37 +0100
committerGitHub <[email protected]>2021-06-13 13:49:37 +0100
commitcc6d761a99ab3b7e28ed13ca3839358f3341da4d (patch)
treed9d180d516ddbafc7eb950f401e9a8ab3f1e88fe /crates/hir/src/lib.rs
parent3f53a5dd724cbc7aa20280cddba44c7d2c0c8a6d (diff)
parent6383252cc2770545505d40217732f14e93a396c4 (diff)
Merge #9246
9246: internal: unified missing fields diagnostic r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r--crates/hir/src/lib.rs130
1 files changed, 68 insertions, 62 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index ff6c68dbc..373134f62 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -88,9 +88,9 @@ pub use crate::{
88 diagnostics::{ 88 diagnostics::{
89 AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, InternalBailedOut, MacroError, 89 AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, InternalBailedOut, MacroError,
90 MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, 90 MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr,
91 MissingPatFields, MissingUnsafe, NoSuchField, RemoveThisSemicolon, 91 MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap,
92 ReplaceFilterMapNextWithFindMap, UnimplementedBuiltinMacro, UnresolvedExternCrate, 92 UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall,
93 UnresolvedImport, UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, 93 UnresolvedModule, UnresolvedProcMacro,
94 }, 94 },
95 has_source::HasSource, 95 has_source::HasSource,
96 semantics::{PathResolution, Semantics, SemanticsScope}, 96 semantics::{PathResolution, Semantics, SemanticsScope},
@@ -609,23 +609,21 @@ impl Module {
609 } 609 }
610 for decl in self.declarations(db) { 610 for decl in self.declarations(db) {
611 match decl { 611 match decl {
612 crate::ModuleDef::Function(f) => f.diagnostics(db, sink, internal_diagnostics), 612 ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink, internal_diagnostics)),
613 crate::ModuleDef::Module(m) => { 613 ModuleDef::Module(m) => {
614 // Only add diagnostics from inline modules 614 // Only add diagnostics from inline modules
615 if def_map[m.id.local_id].origin.is_inline() { 615 if def_map[m.id.local_id].origin.is_inline() {
616 acc.extend(m.diagnostics(db, sink, internal_diagnostics)) 616 acc.extend(m.diagnostics(db, sink, internal_diagnostics))
617 } 617 }
618 } 618 }
619 _ => { 619 _ => decl.diagnostics(db, sink),
620 decl.diagnostics(db, sink);
621 }
622 } 620 }
623 } 621 }
624 622
625 for impl_def in self.impl_defs(db) { 623 for impl_def in self.impl_defs(db) {
626 for item in impl_def.items(db) { 624 for item in impl_def.items(db) {
627 if let AssocItem::Function(f) = item { 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 db: &dyn HirDatabase, 1031 db: &dyn HirDatabase,
1034 sink: &mut DiagnosticSink, 1032 sink: &mut DiagnosticSink,
1035 internal_diagnostics: bool, 1033 internal_diagnostics: bool,
1036 ) { 1034 ) -> Vec<AnyDiagnostic> {
1035 let mut acc: Vec<AnyDiagnostic> = Vec::new();
1037 let krate = self.module(db).id.krate(); 1036 let krate = self.module(db).id.krate();
1038 1037
1039 let source_map = db.body_with_source_map(self.id.into()).1; 1038 let source_map = db.body_with_source_map(self.id.into()).1;
@@ -1099,64 +1098,70 @@ impl Function {
1099 BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics) 1098 BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics)
1100 { 1099 {
1101 match diagnostic { 1100 match diagnostic {
1102 BodyValidationDiagnostic::RecordLiteralMissingFields { 1101 BodyValidationDiagnostic::RecordMissingFields {
1103 record_expr, 1102 record,
1104 variant, 1103 variant,
1105 missed_fields, 1104 missed_fields,
1106 } => match source_map.expr_syntax(record_expr) { 1105 } => {
1107 Ok(source_ptr) => { 1106 let variant_data = variant.variant_data(db.upcast());
1108 let root = source_ptr.file_syntax(db.upcast()); 1107 let missed_fields = missed_fields
1109 if let ast::Expr::RecordExpr(record_expr) = &source_ptr.value.to_node(&root) 1108 .into_iter()
1110 { 1109 .map(|idx| variant_data.fields()[idx].name.clone())
1111 if let Some(_) = record_expr.record_expr_field_list() { 1110 .collect();
1112 let variant_data = variant.variant_data(db.upcast()); 1111
1113 let missed_fields = missed_fields 1112 match record {
1114 .into_iter() 1113 Either::Left(record_expr) => match source_map.expr_syntax(record_expr) {
1115 .map(|idx| variant_data.fields()[idx].name.clone()) 1114 Ok(source_ptr) => {
1116 .collect(); 1115 let root = source_ptr.file_syntax(db.upcast());
1117 sink.push(MissingFields { 1116 if let ast::Expr::RecordExpr(record_expr) =
1118 file: source_ptr.file_id, 1117 &source_ptr.value.to_node(&root)
1119 field_list_parent: AstPtr::new(record_expr), 1118 {
1120 field_list_parent_path: record_expr 1119 if let Some(_) = record_expr.record_expr_field_list() {
1121 .path() 1120 acc.push(
1122 .map(|path| AstPtr::new(&path)), 1121 MissingFields {
1123 missed_fields, 1122 file: source_ptr.file_id,
1124 }) 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 } 1136 Err(SyntheticSyntax) => (),
1127 } 1137 },
1128 Err(SyntheticSyntax) => (), 1138 Either::Right(record_pat) => match source_map.pat_syntax(record_pat) {
1129 }, 1139 Ok(source_ptr) => {
1130 BodyValidationDiagnostic::RecordPatMissingFields { 1140 if let Some(expr) = source_ptr.value.as_ref().left() {
1131 record_pat, 1141 let root = source_ptr.file_syntax(db.upcast());
1132 variant, 1142 if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) {
1133 missed_fields, 1143 if let Some(_) = record_pat.record_pat_field_list() {
1134 } => match source_map.pat_syntax(record_pat) { 1144 acc.push(
1135 Ok(source_ptr) => { 1145 MissingFields {
1136 if let Some(expr) = source_ptr.value.as_ref().left() { 1146 file: source_ptr.file_id,
1137 let root = source_ptr.file_syntax(db.upcast()); 1147 field_list_parent: Either::Right(AstPtr::new(
1138 if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { 1148 &record_pat,
1139 if let Some(_) = record_pat.record_pat_field_list() { 1149 )),
1140 let variant_data = variant.variant_data(db.upcast()); 1150 field_list_parent_path: record_pat
1141 let missed_fields = missed_fields 1151 .path()
1142 .into_iter() 1152 .map(|path| AstPtr::new(&path)),
1143 .map(|idx| variant_data.fields()[idx].name.clone()) 1153 missed_fields,
1144 .collect(); 1154 }
1145 sink.push(MissingPatFields { 1155 .into(),
1146 file: source_ptr.file_id, 1156 )
1147 field_list_parent: AstPtr::new(&record_pat), 1157 }
1148 field_list_parent_path: record_pat 1158 }
1149 .path()
1150 .map(|path| AstPtr::new(&path)),
1151 missed_fields,
1152 })
1153 } 1159 }
1154 } 1160 }
1155 } 1161 Err(SyntheticSyntax) => (),
1162 },
1156 } 1163 }
1157 Err(SyntheticSyntax) => (), 1164 }
1158 },
1159
1160 BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => { 1165 BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => {
1161 if let Ok(next_source_ptr) = source_map.expr_syntax(method_call_expr) { 1166 if let Ok(next_source_ptr) = source_map.expr_syntax(method_call_expr) {
1162 sink.push(ReplaceFilterMapNextWithFindMap { 1167 sink.push(ReplaceFilterMapNextWithFindMap {
@@ -1234,6 +1239,7 @@ impl Function {
1234 for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) { 1239 for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) {
1235 sink.push(diag) 1240 sink.push(diag)
1236 } 1241 }
1242 acc
1237 } 1243 }
1238 1244
1239 /// Whether this function declaration has a definition. 1245 /// Whether this function declaration has a definition.