Skip to content

Commit 56abc0a

Browse files
committed
Auto merge of #15971 - Young-Flash:fix_match_arm, r=lnicola
fix: don't make `MissingMatchArms` diagnostic for empty match body before <img width="423" alt="before" src="https://github.com/rust-lang/rust-analyzer/assets/71162630/5c0e46fb-0c03-42f2-96ff-8e5245c25965"> after <img width="423" alt="after" src="https://github.com/rust-lang/rust-analyzer/assets/71162630/e2479dc5-3634-479b-af29-0b0ec7dc4a4f"> close #15954
2 parents c7c582a + b46f378 commit 56abc0a

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,31 @@ pub(crate) fn missing_match_arms(
1717

1818
#[cfg(test)]
1919
mod tests {
20-
use crate::tests::check_diagnostics;
20+
use crate::{
21+
tests::{check_diagnostics, check_diagnostics_with_config},
22+
DiagnosticsConfig,
23+
};
2124

2225
#[track_caller]
2326
fn check_diagnostics_no_bails(ra_fixture: &str) {
2427
cov_mark::check_count!(validate_match_bailed_out, 0);
2528
crate::tests::check_diagnostics(ra_fixture)
2629
}
2730

31+
#[test]
32+
fn empty_body() {
33+
let mut config = DiagnosticsConfig::test_sample();
34+
config.disabled.insert("syntax-error".to_string());
35+
check_diagnostics_with_config(
36+
config,
37+
r#"
38+
fn main() {
39+
match 0;
40+
}
41+
"#,
42+
);
43+
}
44+
2845
#[test]
2946
fn empty_tuple() {
3047
check_diagnostics_no_bails(

0 commit comments

Comments
 (0)