aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/diagnostics.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-09 16:34:43 +0100
committerGitHub <[email protected]>2020-07-09 16:34:43 +0100
commit89c7c559953f103f224caacad6c9497d36660c76 (patch)
treefff7cbf2b489053af801e075c51288d7d7d6afca /crates/ra_hir_ty/src/diagnostics.rs
parentf1d084fbd9504497aed24b907b03247bfcd31675 (diff)
parentf4a9d9a00f0462bce92ddbac24cb91825c8ab192 (diff)
Merge #5270
5270: Add argument count mismatch diagnostic r=matklad a=jonas-schievink Closes https://github.com/rust-analyzer/rust-analyzer/issues/4025. This currently has one false positive on this line, where `max` is resolved to `Iterator::max` instead of `Ord::max`: https://github.com/rust-analyzer/rust-analyzer/blob/8aa10c00a4c5b957d459fac5a103cd9688e8dcdd/crates/expect/src/lib.rs#L263 (I have no idea why it thinks that `usize` is an `Iterator`) TODO: * [x] Tests * [x] Improve diagnostic text for method calls Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 0289911de..5b0dda634 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -197,3 +197,33 @@ 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 let s = if self.expected == 1 { "" } else { "s" };
212 format!("Expected {} argument{}, found {}", self.expected, s, self.found)
213 }
214 fn source(&self) -> InFile<SyntaxNodePtr> {
215 InFile { file_id: self.file, value: self.call_expr.clone().into() }
216 }
217 fn as_any(&self) -> &(dyn Any + Send + 'static) {
218 self
219 }
220}
221
222impl AstDiagnostic for MismatchedArgCount {
223 type AST = ast::CallExpr;
224 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
225 let root = db.parse_or_expand(self.source().file_id).unwrap();
226 let node = self.source().value.to_node(&root);
227 ast::CallExpr::cast(node).unwrap()
228 }
229}