From b292e1b9da39813e2739cb450c263e7502c97c8d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 21:44:31 +0300 Subject: internal: refactor missing match arms diagnostics --- crates/hir/src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'crates/hir/src/lib.rs') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index fc147ade3..2e794ff4a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1209,11 +1209,14 @@ impl Function { if let (Some(match_expr), Some(arms)) = (match_expr.expr(), match_expr.match_arm_list()) { - sink.push(MissingMatchArms { - file: source_ptr.file_id, - match_expr: AstPtr::new(&match_expr), - arms: AstPtr::new(&arms), - }) + acc.push( + MissingMatchArms { + file: source_ptr.file_id, + match_expr: AstPtr::new(&match_expr), + arms: AstPtr::new(&arms), + } + .into(), + ) } } } -- cgit v1.2.3 From 935c53b92eea7c288b781ecd68436c9733ec8a83 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 21:55:51 +0300 Subject: internal: use cov-mark rather than bailing out diagnostic --- crates/hir/src/lib.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'crates/hir/src/lib.rs') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 2e794ff4a..7f689cd41 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -86,8 +86,8 @@ use crate::{ pub use crate::{ attrs::{HasAttrs, Namespace}, diagnostics::{ - AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, InternalBailedOut, - MacroError, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, + AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, MacroError, + MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, @@ -461,7 +461,6 @@ impl Module { self, db: &dyn HirDatabase, sink: &mut DiagnosticSink, - internal_diagnostics: bool, ) -> Vec { let _p = profile::span("Module::diagnostics").detail(|| { format!("{:?}", self.name(db).map_or("".into(), |name| name.to_string())) @@ -619,11 +618,11 @@ impl Module { } for decl in self.declarations(db) { match decl { - ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink, internal_diagnostics)), + ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink)), ModuleDef::Module(m) => { // Only add diagnostics from inline modules if def_map[m.id.local_id].origin.is_inline() { - acc.extend(m.diagnostics(db, sink, internal_diagnostics)) + acc.extend(m.diagnostics(db, sink)) } } _ => acc.extend(decl.diagnostics(db)), @@ -633,7 +632,7 @@ impl Module { for impl_def in self.impl_defs(db) { for item in impl_def.items(db) { if let AssocItem::Function(f) = item { - acc.extend(f.diagnostics(db, sink, internal_diagnostics)); + acc.extend(f.diagnostics(db, sink)); } } } @@ -1040,7 +1039,6 @@ impl Function { self, db: &dyn HirDatabase, sink: &mut DiagnosticSink, - internal_diagnostics: bool, ) -> Vec { let mut acc: Vec = Vec::new(); let krate = self.module(db).id.krate(); @@ -1100,9 +1098,7 @@ impl Function { } } - for diagnostic in - BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics) - { + for diagnostic in BodyValidationDiagnostic::collect(db, self.id.into()) { match diagnostic { BodyValidationDiagnostic::RecordMissingFields { record, @@ -1223,18 +1219,6 @@ impl Function { Err(SyntheticSyntax) => (), } } - BodyValidationDiagnostic::InternalBailedOut { pat } => { - match source_map.pat_syntax(pat) { - Ok(source_ptr) => { - let pat_syntax_ptr = source_ptr.value.either(Into::into, Into::into); - sink.push(InternalBailedOut { - file: source_ptr.file_id, - pat_syntax_ptr, - }); - } - Err(SyntheticSyntax) => (), - } - } } } -- cgit v1.2.3 From ff52167c9a8dd6f99a56a35eae8d634d0ddf1286 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 22:05:47 +0300 Subject: internal: kill diagnostic sink --- crates/hir/src/lib.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'crates/hir/src/lib.rs') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 7f689cd41..ce38396d0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -27,7 +27,6 @@ mod attrs; mod has_source; pub mod diagnostics; -pub mod diagnostics_sink; pub mod db; mod display; @@ -78,10 +77,7 @@ use syntax::{ }; use tt::{Ident, Leaf, Literal, TokenTree}; -use crate::{ - db::{DefDatabase, HirDatabase}, - diagnostics_sink::DiagnosticSink, -}; +use crate::db::{DefDatabase, HirDatabase}; pub use crate::{ attrs::{HasAttrs, Namespace}, @@ -457,15 +453,10 @@ impl Module { self.id.def_map(db.upcast())[self.id.local_id].scope.visibility_of((*def).into()) } - pub fn diagnostics( - self, - db: &dyn HirDatabase, - sink: &mut DiagnosticSink, - ) -> Vec { + pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec) { let _p = profile::span("Module::diagnostics").detail(|| { format!("{:?}", self.name(db).map_or("".into(), |name| name.to_string())) }); - let mut acc: Vec = Vec::new(); let def_map = self.id.def_map(db.upcast()); for diag in def_map.diagnostics() { if diag.in_module != self.id.local_id { @@ -618,11 +609,11 @@ impl Module { } for decl in self.declarations(db) { match decl { - ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink)), + ModuleDef::Function(f) => f.diagnostics(db, acc), ModuleDef::Module(m) => { // Only add diagnostics from inline modules if def_map[m.id.local_id].origin.is_inline() { - acc.extend(m.diagnostics(db, sink)) + m.diagnostics(db, acc) } } _ => acc.extend(decl.diagnostics(db)), @@ -632,11 +623,10 @@ impl Module { for impl_def in self.impl_defs(db) { for item in impl_def.items(db) { if let AssocItem::Function(f) = item { - acc.extend(f.diagnostics(db, sink)); + f.diagnostics(db, acc); } } } - acc } pub fn declarations(self, db: &dyn HirDatabase) -> Vec { @@ -1035,12 +1025,7 @@ impl Function { db.function_data(self.id).is_async() } - pub fn diagnostics( - self, - db: &dyn HirDatabase, - sink: &mut DiagnosticSink, - ) -> Vec { - let mut acc: Vec = Vec::new(); + pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec) { let krate = self.module(db).id.krate(); let source_map = db.body_with_source_map(self.id.into()).1; @@ -1225,7 +1210,6 @@ impl Function { for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) { acc.push(diag.into()) } - acc } /// Whether this function declaration has a definition. -- cgit v1.2.3