From 8d391ec981562785ec92ce3afe950972c523f925 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 20:06:25 +0300 Subject: internal: refactor mismatched args count diagnostic --- crates/hir/src/diagnostics.rs | 26 ++------------------------ crates/hir/src/lib.rs | 9 +++------ 2 files changed, 5 insertions(+), 30 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index f7bf63215..f839616ce 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -35,6 +35,7 @@ diagnostics![ BreakOutsideOfLoop, InactiveCode, MacroError, + MismatchedArgCount, MissingFields, MissingUnsafe, NoSuchField, @@ -143,36 +144,13 @@ impl Diagnostic for ReplaceFilterMapNextWithFindMap { } } -// Diagnostic: mismatched-arg-count -// -// This diagnostic is triggered if a function is invoked with an incorrect amount of arguments. #[derive(Debug)] pub struct MismatchedArgCount { - pub file: HirFileId, - pub call_expr: AstPtr, + pub call_expr: InFile>, pub expected: usize, pub found: usize, } -impl Diagnostic for MismatchedArgCount { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("mismatched-arg-count") - } - fn message(&self) -> String { - let s = if self.expected == 1 { "" } else { "s" }; - format!("Expected {} argument{}, found {}", self.expected, s, self.found) - } - fn display_source(&self) -> InFile { - InFile { file_id: self.file, value: self.call_expr.clone().into() } - } - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } - fn is_experimental(&self) -> bool { - true - } -} - #[derive(Debug)] pub struct RemoveThisSemicolon { pub file: HirFileId, diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 16f862707..c1af5f097 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1176,12 +1176,9 @@ impl Function { } BodyValidationDiagnostic::MismatchedArgCount { call_expr, expected, found } => { match source_map.expr_syntax(call_expr) { - Ok(source_ptr) => sink.push(MismatchedArgCount { - file: source_ptr.file_id, - call_expr: source_ptr.value, - expected, - found, - }), + Ok(source_ptr) => acc.push( + MismatchedArgCount { call_expr: source_ptr, expected, found }.into(), + ), Err(SyntheticSyntax) => (), } } -- cgit v1.2.3