Skip to content

Commit

Permalink
Auto merge of #15971 - Young-Flash:fix_match_arm, r=lnicola
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Nov 30, 2023
2 parents c7c582a + b46f378 commit 56abc0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
25 changes: 14 additions & 11 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
_ => {}
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion crates/ide-diagnostics/src/handlers/missing_match_arms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,31 @@ pub(crate) fn missing_match_arms(

#[cfg(test)]
mod tests {
use crate::tests::check_diagnostics;
use crate::{
tests::{check_diagnostics, check_diagnostics_with_config},
DiagnosticsConfig,
};

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

#[test]
fn empty_body() {
let mut config = DiagnosticsConfig::test_sample();
config.disabled.insert("syntax-error".to_string());
check_diagnostics_with_config(
config,
r#"
fn main() {
match 0;
}
"#,
);
}

#[test]
fn empty_tuple() {
check_diagnostics_no_bails(
Expand Down

0 comments on commit 56abc0a

Please sign in to comment.