Skip to content

Commit cab9148

Browse files
committed
fix: don't make MissingMatchArms diagnostic for empty match body
1 parent 4513651 commit cab9148

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

crates/hir/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,17 +1914,20 @@ impl DefWithBody {
19141914
if let ast::Expr::MatchExpr(match_expr) =
19151915
&source_ptr.value.to_node(&root)
19161916
{
1917-
if let Some(scrut_expr) = match_expr.expr() {
1918-
acc.push(
1919-
MissingMatchArms {
1920-
scrutinee_expr: InFile::new(
1921-
source_ptr.file_id,
1922-
AstPtr::new(&scrut_expr),
1923-
),
1924-
uncovered_patterns,
1925-
}
1926-
.into(),
1927-
);
1917+
match match_expr.expr() {
1918+
Some(scrut_expr) if match_expr.match_arm_list().is_some() => {
1919+
acc.push(
1920+
MissingMatchArms {
1921+
scrutinee_expr: InFile::new(
1922+
source_ptr.file_id,
1923+
AstPtr::new(&scrut_expr),
1924+
),
1925+
uncovered_patterns,
1926+
}
1927+
.into(),
1928+
);
1929+
}
1930+
_ => {}
19281931
}
19291932
}
19301933
}

crates/ide-diagnostics/src/handlers/missing_match_arms.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ mod tests {
2525
crate::tests::check_diagnostics(ra_fixture)
2626
}
2727

28+
#[test]
29+
fn empty_body() {
30+
check_diagnostics_no_bails(
31+
r#"
32+
fn main() {
33+
match 0;
34+
//^ error: Syntax Error: expected `{`
35+
}
36+
"#,
37+
);
38+
}
39+
2840
#[test]
2941
fn empty_tuple() {
3042
check_diagnostics_no_bails(

0 commit comments

Comments
 (0)