diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-13 20:06:18 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-13 20:06:18 +0100 |
commit | 8c5c0ef7b910ffafc9c684cb7076149ab79f4bdd (patch) | |
tree | cb85647c41d797b885ac579312043df4b3112648 /crates/hir/src/lib.rs | |
parent | 76530664e7f01091e0d820eb49bf59db1f06115c (diff) | |
parent | ff52167c9a8dd6f99a56a35eae8d634d0ddf1286 (diff) |
Merge #9256
9256: internal: kill diagnostic sink 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.rs | 63 |
1 files changed, 17 insertions, 46 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index fc147ade3..ce38396d0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -27,7 +27,6 @@ mod attrs; | |||
27 | mod has_source; | 27 | mod has_source; |
28 | 28 | ||
29 | pub mod diagnostics; | 29 | pub mod diagnostics; |
30 | pub mod diagnostics_sink; | ||
31 | pub mod db; | 30 | pub mod db; |
32 | 31 | ||
33 | mod display; | 32 | mod display; |
@@ -78,16 +77,13 @@ use syntax::{ | |||
78 | }; | 77 | }; |
79 | use tt::{Ident, Leaf, Literal, TokenTree}; | 78 | use tt::{Ident, Leaf, Literal, TokenTree}; |
80 | 79 | ||
81 | use crate::{ | 80 | use crate::db::{DefDatabase, HirDatabase}; |
82 | db::{DefDatabase, HirDatabase}, | ||
83 | diagnostics_sink::DiagnosticSink, | ||
84 | }; | ||
85 | 81 | ||
86 | pub use crate::{ | 82 | pub use crate::{ |
87 | attrs::{HasAttrs, Namespace}, | 83 | attrs::{HasAttrs, Namespace}, |
88 | diagnostics::{ | 84 | diagnostics::{ |
89 | AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, InternalBailedOut, | 85 | AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, MacroError, |
90 | MacroError, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, | 86 | MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, |
91 | MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap, | 87 | MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap, |
92 | UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, | 88 | UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, |
93 | UnresolvedModule, UnresolvedProcMacro, | 89 | UnresolvedModule, UnresolvedProcMacro, |
@@ -457,16 +453,10 @@ impl Module { | |||
457 | self.id.def_map(db.upcast())[self.id.local_id].scope.visibility_of((*def).into()) | 453 | self.id.def_map(db.upcast())[self.id.local_id].scope.visibility_of((*def).into()) |
458 | } | 454 | } |
459 | 455 | ||
460 | pub fn diagnostics( | 456 | pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) { |
461 | self, | ||
462 | db: &dyn HirDatabase, | ||
463 | sink: &mut DiagnosticSink, | ||
464 | internal_diagnostics: bool, | ||
465 | ) -> Vec<AnyDiagnostic> { | ||
466 | let _p = profile::span("Module::diagnostics").detail(|| { | 457 | let _p = profile::span("Module::diagnostics").detail(|| { |
467 | format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string())) | 458 | format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string())) |
468 | }); | 459 | }); |
469 | let mut acc: Vec<AnyDiagnostic> = Vec::new(); | ||
470 | let def_map = self.id.def_map(db.upcast()); | 460 | let def_map = self.id.def_map(db.upcast()); |
471 | for diag in def_map.diagnostics() { | 461 | for diag in def_map.diagnostics() { |
472 | if diag.in_module != self.id.local_id { | 462 | if diag.in_module != self.id.local_id { |
@@ -619,11 +609,11 @@ impl Module { | |||
619 | } | 609 | } |
620 | for decl in self.declarations(db) { | 610 | for decl in self.declarations(db) { |
621 | match decl { | 611 | match decl { |
622 | ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink, internal_diagnostics)), | 612 | ModuleDef::Function(f) => f.diagnostics(db, acc), |
623 | ModuleDef::Module(m) => { | 613 | ModuleDef::Module(m) => { |
624 | // Only add diagnostics from inline modules | 614 | // Only add diagnostics from inline modules |
625 | if def_map[m.id.local_id].origin.is_inline() { | 615 | if def_map[m.id.local_id].origin.is_inline() { |
626 | acc.extend(m.diagnostics(db, sink, internal_diagnostics)) | 616 | m.diagnostics(db, acc) |
627 | } | 617 | } |
628 | } | 618 | } |
629 | _ => acc.extend(decl.diagnostics(db)), | 619 | _ => acc.extend(decl.diagnostics(db)), |
@@ -633,11 +623,10 @@ impl Module { | |||
633 | for impl_def in self.impl_defs(db) { | 623 | for impl_def in self.impl_defs(db) { |
634 | for item in impl_def.items(db) { | 624 | for item in impl_def.items(db) { |
635 | if let AssocItem::Function(f) = item { | 625 | if let AssocItem::Function(f) = item { |
636 | acc.extend(f.diagnostics(db, sink, internal_diagnostics)); | 626 | f.diagnostics(db, acc); |
637 | } | 627 | } |
638 | } | 628 | } |
639 | } | 629 | } |
640 | acc | ||
641 | } | 630 | } |
642 | 631 | ||
643 | pub fn declarations(self, db: &dyn HirDatabase) -> Vec<ModuleDef> { | 632 | pub fn declarations(self, db: &dyn HirDatabase) -> Vec<ModuleDef> { |
@@ -1036,13 +1025,7 @@ impl Function { | |||
1036 | db.function_data(self.id).is_async() | 1025 | db.function_data(self.id).is_async() |
1037 | } | 1026 | } |
1038 | 1027 | ||
1039 | pub fn diagnostics( | 1028 | pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) { |
1040 | self, | ||
1041 | db: &dyn HirDatabase, | ||
1042 | sink: &mut DiagnosticSink, | ||
1043 | internal_diagnostics: bool, | ||
1044 | ) -> Vec<AnyDiagnostic> { | ||
1045 | let mut acc: Vec<AnyDiagnostic> = Vec::new(); | ||
1046 | let krate = self.module(db).id.krate(); | 1029 | let krate = self.module(db).id.krate(); |
1047 | 1030 | ||
1048 | let source_map = db.body_with_source_map(self.id.into()).1; | 1031 | let source_map = db.body_with_source_map(self.id.into()).1; |
@@ -1100,9 +1083,7 @@ impl Function { | |||
1100 | } | 1083 | } |
1101 | } | 1084 | } |
1102 | 1085 | ||
1103 | for diagnostic in | 1086 | for diagnostic in BodyValidationDiagnostic::collect(db, self.id.into()) { |
1104 | BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics) | ||
1105 | { | ||
1106 | match diagnostic { | 1087 | match diagnostic { |
1107 | BodyValidationDiagnostic::RecordMissingFields { | 1088 | BodyValidationDiagnostic::RecordMissingFields { |
1108 | record, | 1089 | record, |
@@ -1209,36 +1190,26 @@ impl Function { | |||
1209 | if let (Some(match_expr), Some(arms)) = | 1190 | if let (Some(match_expr), Some(arms)) = |
1210 | (match_expr.expr(), match_expr.match_arm_list()) | 1191 | (match_expr.expr(), match_expr.match_arm_list()) |
1211 | { | 1192 | { |
1212 | sink.push(MissingMatchArms { | 1193 | acc.push( |
1213 | file: source_ptr.file_id, | 1194 | MissingMatchArms { |
1214 | match_expr: AstPtr::new(&match_expr), | 1195 | file: source_ptr.file_id, |
1215 | arms: AstPtr::new(&arms), | 1196 | match_expr: AstPtr::new(&match_expr), |
1216 | }) | 1197 | arms: AstPtr::new(&arms), |
1198 | } | ||
1199 | .into(), | ||
1200 | ) | ||
1217 | } | 1201 | } |
1218 | } | 1202 | } |
1219 | } | 1203 | } |
1220 | Err(SyntheticSyntax) => (), | 1204 | Err(SyntheticSyntax) => (), |
1221 | } | 1205 | } |
1222 | } | 1206 | } |
1223 | BodyValidationDiagnostic::InternalBailedOut { pat } => { | ||
1224 | match source_map.pat_syntax(pat) { | ||
1225 | Ok(source_ptr) => { | ||
1226 | let pat_syntax_ptr = source_ptr.value.either(Into::into, Into::into); | ||
1227 | sink.push(InternalBailedOut { | ||
1228 | file: source_ptr.file_id, | ||
1229 | pat_syntax_ptr, | ||
1230 | }); | ||
1231 | } | ||
1232 | Err(SyntheticSyntax) => (), | ||
1233 | } | ||
1234 | } | ||
1235 | } | 1207 | } |
1236 | } | 1208 | } |
1237 | 1209 | ||
1238 | for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) { | 1210 | for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) { |
1239 | acc.push(diag.into()) | 1211 | acc.push(diag.into()) |
1240 | } | 1212 | } |
1241 | acc | ||
1242 | } | 1213 | } |
1243 | 1214 | ||
1244 | /// Whether this function declaration has a definition. | 1215 | /// Whether this function declaration has a definition. |