From 63ce2c7b5fd96e6688796f2ddd1cd7316df8d11d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 8 Jul 2020 19:58:45 +0200 Subject: Add argument count mismatch diagnostic --- crates/ra_hir_ty/src/diagnostics.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'crates/ra_hir_ty/src/diagnostics.rs') diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 0289911de..daac669e6 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs @@ -197,3 +197,32 @@ impl AstDiagnostic for MissingUnsafe { ast::Expr::cast(node).unwrap() } } + +#[derive(Debug)] +pub struct MismatchedArgCount { + pub file: HirFileId, + pub call_expr: AstPtr, + pub expected: usize, + pub found: usize, +} + +impl Diagnostic for MismatchedArgCount { + fn message(&self) -> String { + format!("Expected {} arguments, found {}", self.expected, self.found) + } + fn source(&self) -> InFile { + InFile { file_id: self.file, value: self.call_expr.clone().into() } + } + fn as_any(&self) -> &(dyn Any + Send + 'static) { + self + } +} + +impl AstDiagnostic for MismatchedArgCount { + type AST = ast::CallExpr; + fn ast(&self, db: &dyn AstDatabase) -> Self::AST { + let root = db.parse_or_expand(self.source().file_id).unwrap(); + let node = self.source().value.to_node(&root); + ast::CallExpr::cast(node).unwrap() + } +} -- cgit v1.2.3