diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 13:48:54 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 13:48:54 +0100 |
commit | 6383252cc2770545505d40217732f14e93a396c4 (patch) | |
tree | c68f9e02b8ef19b6d4bb70451c202bccbf5858f0 /crates/hir/src/lib.rs | |
parent | c6509a4592b67acc4a99a7ffd6dd688bc6cd29be (diff) |
internal: unified missing fields diagnostic
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r-- | crates/hir/src/lib.rs | 117 |
1 files changed, 60 insertions, 57 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 583d92f20..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}, |
@@ -1098,67 +1098,70 @@ impl Function { | |||
1098 | BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics) | 1098 | BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics) |
1099 | { | 1099 | { |
1100 | match diagnostic { | 1100 | match diagnostic { |
1101 | BodyValidationDiagnostic::RecordLiteralMissingFields { | 1101 | BodyValidationDiagnostic::RecordMissingFields { |
1102 | record_expr, | 1102 | record, |
1103 | variant, | 1103 | variant, |
1104 | missed_fields, | 1104 | missed_fields, |
1105 | } => match source_map.expr_syntax(record_expr) { | 1105 | } => { |
1106 | Ok(source_ptr) => { | 1106 | let variant_data = variant.variant_data(db.upcast()); |
1107 | let root = source_ptr.file_syntax(db.upcast()); | 1107 | let missed_fields = missed_fields |
1108 | if let ast::Expr::RecordExpr(record_expr) = &source_ptr.value.to_node(&root) | 1108 | .into_iter() |
1109 | { | 1109 | .map(|idx| variant_data.fields()[idx].name.clone()) |
1110 | if let Some(_) = record_expr.record_expr_field_list() { | 1110 | .collect(); |
1111 | let variant_data = variant.variant_data(db.upcast()); | 1111 | |
1112 | let missed_fields = missed_fields | 1112 | match record { |
1113 | .into_iter() | 1113 | Either::Left(record_expr) => match source_map.expr_syntax(record_expr) { |
1114 | .map(|idx| variant_data.fields()[idx].name.clone()) | 1114 | Ok(source_ptr) => { |
1115 | .collect(); | 1115 | let root = source_ptr.file_syntax(db.upcast()); |
1116 | acc.push( | 1116 | if let ast::Expr::RecordExpr(record_expr) = |
1117 | MissingFields { | 1117 | &source_ptr.value.to_node(&root) |
1118 | file: source_ptr.file_id, | 1118 | { |
1119 | field_list_parent: AstPtr::new(record_expr), | 1119 | if let Some(_) = record_expr.record_expr_field_list() { |
1120 | field_list_parent_path: record_expr | 1120 | acc.push( |
1121 | .path() | 1121 | MissingFields { |
1122 | .map(|path| AstPtr::new(&path)), | 1122 | file: source_ptr.file_id, |
1123 | missed_fields, | 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 | ) | ||
1124 | } | 1133 | } |
1125 | .into(), | 1134 | } |
1126 | ) | ||
1127 | } | 1135 | } |
1128 | } | 1136 | Err(SyntheticSyntax) => (), |
1129 | } | 1137 | }, |
1130 | Err(SyntheticSyntax) => (), | 1138 | Either::Right(record_pat) => match source_map.pat_syntax(record_pat) { |
1131 | }, | 1139 | Ok(source_ptr) => { |
1132 | BodyValidationDiagnostic::RecordPatMissingFields { | 1140 | if let Some(expr) = source_ptr.value.as_ref().left() { |
1133 | record_pat, | 1141 | let root = source_ptr.file_syntax(db.upcast()); |
1134 | variant, | 1142 | if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { |
1135 | missed_fields, | 1143 | if let Some(_) = record_pat.record_pat_field_list() { |
1136 | } => match source_map.pat_syntax(record_pat) { | 1144 | acc.push( |
1137 | Ok(source_ptr) => { | 1145 | MissingFields { |
1138 | if let Some(expr) = source_ptr.value.as_ref().left() { | 1146 | file: source_ptr.file_id, |
1139 | let root = source_ptr.file_syntax(db.upcast()); | 1147 | field_list_parent: Either::Right(AstPtr::new( |
1140 | if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { | 1148 | &record_pat, |
1141 | if let Some(_) = record_pat.record_pat_field_list() { | 1149 | )), |
1142 | let variant_data = variant.variant_data(db.upcast()); | 1150 | field_list_parent_path: record_pat |
1143 | let missed_fields = missed_fields | 1151 | .path() |
1144 | .into_iter() | 1152 | .map(|path| AstPtr::new(&path)), |
1145 | .map(|idx| variant_data.fields()[idx].name.clone()) | 1153 | missed_fields, |
1146 | .collect(); | 1154 | } |
1147 | sink.push(MissingPatFields { | 1155 | .into(), |
1148 | file: source_ptr.file_id, | 1156 | ) |
1149 | field_list_parent: AstPtr::new(&record_pat), | 1157 | } |
1150 | field_list_parent_path: record_pat | 1158 | } |
1151 | .path() | ||
1152 | .map(|path| AstPtr::new(&path)), | ||
1153 | missed_fields, | ||
1154 | }) | ||
1155 | } | 1159 | } |
1156 | } | 1160 | } |
1157 | } | 1161 | Err(SyntheticSyntax) => (), |
1162 | }, | ||
1158 | } | 1163 | } |
1159 | Err(SyntheticSyntax) => (), | 1164 | } |
1160 | }, | ||
1161 | |||
1162 | BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => { | 1165 | BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => { |
1163 | 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) { |
1164 | sink.push(ReplaceFilterMapNextWithFindMap { | 1167 | sink.push(ReplaceFilterMapNextWithFindMap { |