aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/diagnostics.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-07-08 18:58:45 +0100
committerJonas Schievink <[email protected]>2020-07-09 11:16:29 +0100
commit63ce2c7b5fd96e6688796f2ddd1cd7316df8d11d (patch)
tree8e3ce783592c9c136efac6bbf78ffff177c077cc /crates/ra_hir_ty/src/diagnostics.rs
parent91005ecc27427f46529b9372f91e5072dfe5e179 (diff)
Add argument count mismatch diagnostic
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs29
1 files changed, 29 insertions, 0 deletions
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 {
197 ast::Expr::cast(node).unwrap() 197 ast::Expr::cast(node).unwrap()
198 } 198 }
199} 199}
200
201#[derive(Debug)]
202pub struct MismatchedArgCount {
203 pub file: HirFileId,
204 pub call_expr: AstPtr<ast::Expr>,
205 pub expected: usize,
206 pub found: usize,
207}
208
209impl Diagnostic for MismatchedArgCount {
210 fn message(&self) -> String {
211 format!("Expected {} arguments, found {}", self.expected, self.found)
212 }
213 fn source(&self) -> InFile<SyntaxNodePtr> {
214 InFile { file_id: self.file, value: self.call_expr.clone().into() }
215 }
216 fn as_any(&self) -> &(dyn Any + Send + 'static) {
217 self
218 }
219}
220
221impl AstDiagnostic for MismatchedArgCount {
222 type AST = ast::CallExpr;
223 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
224 let root = db.parse_or_expand(self.source().file_id).unwrap();
225 let node = self.source().value.to_node(&root);
226 ast::CallExpr::cast(node).unwrap()
227 }
228}