From fc30c5ccbeba2a102922da497809dd3f812544c4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 21:09:03 +0300 Subject: internal: refactor incorrect case diagnostics --- crates/hir/src/diagnostics.rs | 29 +---------------------------- crates/hir/src/lib.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 36 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index c294a803b..c2d608eb5 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -34,6 +34,7 @@ macro_rules! diagnostics { diagnostics![ BreakOutsideOfLoop, InactiveCode, + IncorrectCase, MacroError, MismatchedArgCount, MissingFields, @@ -195,31 +196,3 @@ impl Diagnostic for InternalBailedOut { } pub use hir_ty::diagnostics::IncorrectCase; - -impl Diagnostic for IncorrectCase { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("incorrect-ident-case") - } - - fn message(&self) -> String { - format!( - "{} `{}` should have {} name, e.g. `{}`", - self.ident_type, - self.ident_text, - self.expected_case.to_string(), - self.suggested_text - ) - } - - fn display_source(&self) -> InFile { - InFile::new(self.file, self.ident.clone().into()) - } - - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } - - fn is_experimental(&self) -> bool { - true - } -} diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index b2731b62f..fc147ade3 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, InternalBailedOut, MacroError, - MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, + AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, InternalBailedOut, + MacroError, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr, MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, @@ -340,7 +340,7 @@ impl ModuleDef { } } - pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { + pub fn diagnostics(self, db: &dyn HirDatabase) -> Vec { let id = match self { ModuleDef::Adt(it) => match it { Adt::Struct(it) => it.id.into(), @@ -353,17 +353,19 @@ impl ModuleDef { ModuleDef::Module(it) => it.id.into(), ModuleDef::Const(it) => it.id.into(), ModuleDef::Static(it) => it.id.into(), - _ => return, + _ => return Vec::new(), }; let module = match self.module(db) { Some(it) => it, - None => return, + None => return Vec::new(), }; + let mut acc = Vec::new(); for diag in hir_ty::diagnostics::validate_module_item(db, module.id.krate(), id) { - sink.push(diag) + acc.push(diag.into()) } + acc } } @@ -624,7 +626,7 @@ impl Module { acc.extend(m.diagnostics(db, sink, internal_diagnostics)) } } - _ => decl.diagnostics(db, sink), + _ => acc.extend(decl.diagnostics(db)), } } @@ -1234,7 +1236,7 @@ impl Function { } for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) { - sink.push(diag) + acc.push(diag.into()) } acc } -- cgit v1.2.3