mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
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 https://github.com/rust-lang/rust-analyzer/issues/15954
This commit is contained in:
commit
56abc0a29c
@ -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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,10 @@ pub(crate) fn missing_match_arms(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::check_diagnostics;
|
use crate::{
|
||||||
|
tests::{check_diagnostics, check_diagnostics_with_config},
|
||||||
|
DiagnosticsConfig,
|
||||||
|
};
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn check_diagnostics_no_bails(ra_fixture: &str) {
|
fn check_diagnostics_no_bails(ra_fixture: &str) {
|
||||||
@ -25,6 +28,20 @@ mod tests {
|
|||||||
crate::tests::check_diagnostics(ra_fixture)
|
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]
|
#[test]
|
||||||
fn empty_tuple() {
|
fn empty_tuple() {
|
||||||
check_diagnostics_no_bails(
|
check_diagnostics_no_bails(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user