fix: don't make MissingMatchArms diagnostic for empty match body

This commit is contained in:
Young-Flash 2023-11-26 22:57:30 +08:00
parent 45136511a5
commit cab91480b2
2 changed files with 26 additions and 11 deletions

View file

@ -1914,17 +1914,20 @@ impl DefWithBody {
if let ast::Expr::MatchExpr(match_expr) = if let ast::Expr::MatchExpr(match_expr) =
&source_ptr.value.to_node(&root) &source_ptr.value.to_node(&root)
{ {
if let Some(scrut_expr) = match_expr.expr() { match match_expr.expr() {
acc.push( Some(scrut_expr) if match_expr.match_arm_list().is_some() => {
MissingMatchArms { acc.push(
scrutinee_expr: InFile::new( MissingMatchArms {
source_ptr.file_id, scrutinee_expr: InFile::new(
AstPtr::new(&scrut_expr), source_ptr.file_id,
), AstPtr::new(&scrut_expr),
uncovered_patterns, ),
} uncovered_patterns,
.into(), }
); .into(),
);
}
_ => {}
} }
} }
} }

View file

@ -25,6 +25,18 @@ mod tests {
crate::tests::check_diagnostics(ra_fixture) crate::tests::check_diagnostics(ra_fixture)
} }
#[test]
fn empty_body() {
check_diagnostics_no_bails(
r#"
fn main() {
match 0;
//^ error: Syntax Error: expected `{`
}
"#,
);
}
#[test] #[test]
fn empty_tuple() { fn empty_tuple() {
check_diagnostics_no_bails( check_diagnostics_no_bails(