mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Fix expansion of OR-patterns in match check
This commit is contained in:
parent
2490ab7718
commit
80fe03877d
1 changed files with 15 additions and 25 deletions
|
@ -539,7 +539,7 @@ impl Matrix {
|
||||||
if let Some(Pat::Or(pat_ids)) = row.get_head().map(|pat_id| pat_id.as_pat(cx)) {
|
if let Some(Pat::Or(pat_ids)) = row.get_head().map(|pat_id| pat_id.as_pat(cx)) {
|
||||||
// Or patterns are expanded here
|
// Or patterns are expanded here
|
||||||
for pat_id in pat_ids {
|
for pat_id in pat_ids {
|
||||||
self.0.push(PatStack::from_pattern(pat_id));
|
self.0.push(row.replace_head_with([pat_id].iter()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.0.push(row);
|
self.0.push(row);
|
||||||
|
@ -1084,6 +1084,20 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn or_pattern_no_diagnostic() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
enum Either {A, B}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match (Either::A, Either::B) {
|
||||||
|
(Either::A | Either::B, _) => (),
|
||||||
|
}
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mismatched_types() {
|
fn mismatched_types() {
|
||||||
// Match statements with arms that don't match the
|
// Match statements with arms that don't match the
|
||||||
|
@ -1335,30 +1349,6 @@ fn bang(never: !) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn or_pattern_panic() {
|
|
||||||
check_diagnostics(
|
|
||||||
r#"
|
|
||||||
pub enum Category { Infinity, Zero }
|
|
||||||
|
|
||||||
fn panic(a: Category, b: Category) {
|
|
||||||
match (a, b) {
|
|
||||||
(Category::Zero | Category::Infinity, _) => (),
|
|
||||||
(_, Category::Zero | Category::Infinity) => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: This is a false positive, but the code used to cause a panic in the match checker,
|
|
||||||
// so this acts as a regression test for that.
|
|
||||||
match (a, b) {
|
|
||||||
//^^^^^^ Missing match arm
|
|
||||||
(Category::Infinity, Category::Infinity) | (Category::Zero, Category::Zero) => (),
|
|
||||||
(Category::Infinity | Category::Zero, _) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unknown_type() {
|
fn unknown_type() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue