diff options
| author | Young-Flash <871946895@qq.com> | 2023-11-26 22:57:30 +0800 |
|---|---|---|
| committer | Young-Flash <871946895@qq.com> | 2023-11-26 22:57:30 +0800 |
| commit | cab91480b22156bd7dce3f79c93f2af373fcdfcf (patch) | |
| tree | 97348822fcbd8fb62c2ba70b9ff1f790b9c71b14 | |
| parent | 45136511a5b4f6b216aba371f541fb2251868c2b (diff) | |
| download | rust-cab91480b22156bd7dce3f79c93f2af373fcdfcf.tar.gz rust-cab91480b22156bd7dce3f79c93f2af373fcdfcf.zip | |
fix: don't make `MissingMatchArms` diagnostic for empty match body
| -rw-r--r-- | crates/hir/src/lib.rs | 25 | ||||
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/missing_match_arms.rs | 12 |
2 files changed, 26 insertions, 11 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 1bfbf7212bf..920c88ccfbc 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1914,17 +1914,20 @@ impl DefWithBody { if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) { - if let Some(scrut_expr) = match_expr.expr() { - acc.push( - MissingMatchArms { - scrutinee_expr: InFile::new( - source_ptr.file_id, - AstPtr::new(&scrut_expr), - ), - uncovered_patterns, - } - .into(), - ); + match match_expr.expr() { + Some(scrut_expr) if match_expr.match_arm_list().is_some() => { + acc.push( + MissingMatchArms { + scrutinee_expr: InFile::new( + source_ptr.file_id, + AstPtr::new(&scrut_expr), + ), + uncovered_patterns, + } + .into(), + ); + } + _ => {} } } } diff --git a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs index 84267d3d906..3f2a6eafb0b 100644 --- a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs +++ b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs @@ -26,6 +26,18 @@ mod tests { } #[test] + fn empty_body() { + check_diagnostics_no_bails( + r#" +fn main() { + match 0; + //^ error: Syntax Error: expected `{` +} +"#, + ); + } + + #[test] fn empty_tuple() { check_diagnostics_no_bails( r#" |
