aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-07 13:53:47 +0100
committerGitHub <[email protected]>2020-04-07 13:53:47 +0100
commit97b963b44b9da1fca4229da4c8744fa88c25780b (patch)
treef25e0db350072cf8d084ce81adcaeeeaac3f4c42 /crates/ra_ide
parentb7e5d94bda362ffc21174a79aa0be113c3288e1e (diff)
parent9fc1f51b7ade2cda7d410450ab1347311eb074af (diff)
Merge #3706
3706: missing match arms diagnostic r=flodiebold a=JoshMcguigan Following up on https://github.com/rust-analyzer/rust-analyzer/pull/3689#issuecomment-602718222, this PR creates a missing match arms diagnostic. At the moment this is a very early draft, but I wanted to open it just to get some initial feedback. Initial questions: * Have I roughly created the correct boilerplate? * Inside the new `validate_match` function: * Am I correct in thinking I want to do validation by comparing the match arms against `match_expr`? And when analyzing `match_expr` I should be looking at it as a `hir_def::expr::Expr`? * I mostly copied the chained if-let statements from the struct validation. Shouldn't there be a non-failable way to get an AstPtr from the hir data structures? Thanks for all the guidance. Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/diagnostics.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index c1d7ddaf2..901ad104c 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -101,6 +101,14 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
101 fix, 101 fix,
102 }) 102 })
103 }) 103 })
104 .on::<hir::diagnostics::MissingMatchArms, _>(|d| {
105 res.borrow_mut().push(Diagnostic {
106 range: d.highlight_range(),
107 message: d.message(),
108 severity: Severity::Error,
109 fix: None,
110 })
111 })
104 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| { 112 .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {
105 let node = d.ast(db); 113 let node = d.ast(db);
106 let replacement = format!("Ok({})", node.syntax()); 114 let replacement = format!("Ok({})", node.syntax());
@@ -291,7 +299,7 @@ mod tests {
291 fn check_no_diagnostic(content: &str) { 299 fn check_no_diagnostic(content: &str) {
292 let (analysis, file_id) = single_file(content); 300 let (analysis, file_id) = single_file(content);
293 let diagnostics = analysis.diagnostics(file_id).unwrap(); 301 let diagnostics = analysis.diagnostics(file_id).unwrap();
294 assert_eq!(diagnostics.len(), 0); 302 assert_eq!(diagnostics.len(), 0, "expected no diagnostic, found one");
295 } 303 }
296 304
297 #[test] 305 #[test]