Auto merge of #13945 - bvanjoi:orpat-match, r=lnicola

fix: check orpat in missing match

fixed #13942
This commit is contained in:
bors 2023-01-14 13:37:30 +00:00
commit ce86f12e8d

View file

@ -269,6 +269,7 @@ fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool {
(Pat::TuplePat(tpat), Pat::TuplePat(tvar)) => { (Pat::TuplePat(tpat), Pat::TuplePat(tvar)) => {
tpat.fields().zip(tvar.fields()).all(|(p, v)| does_pat_match_variant(&p, &v)) tpat.fields().zip(tvar.fields()).all(|(p, v)| does_pat_match_variant(&p, &v))
} }
(Pat::OrPat(opat), _) => opat.pats().any(|p| does_pat_match_variant(&p, var)),
_ => utils::does_pat_match_variant(pat, var), _ => utils::does_pat_match_variant(pat, var),
} }
} }
@ -525,6 +526,19 @@ fn foo(a: bool) {
add_missing_match_arms, add_missing_match_arms,
r#" r#"
fn foo(a: bool) { fn foo(a: bool) {
match (a, a)$0 {
(true | false, true) => {}
(true, false) => {}
(false, false) => {}
}
}
"#,
);
check_assist_not_applicable(
add_missing_match_arms,
r#"
fn foo(a: bool) {
match (a, a)$0 { match (a, a)$0 {
(true, true) => {} (true, true) => {}
(true, false) => {} (true, false) => {}
@ -565,6 +579,26 @@ fn foo(a: bool) {
add_missing_match_arms, add_missing_match_arms,
r#" r#"
fn foo(a: bool) { fn foo(a: bool) {
match (a, a)$0 {
(true | false, true) => {}
}
}
"#,
r#"
fn foo(a: bool) {
match (a, a) {
(true | false, true) => {}
$0(true, false) => todo!(),
(false, false) => todo!(),
}
}
"#,
);
check_assist(
add_missing_match_arms,
r#"
fn foo(a: bool) {
match (a, a)$0 { match (a, a)$0 {
(false, true) => {} (false, true) => {}
} }
@ -882,6 +916,33 @@ fn main() {
} }
"#, "#,
); );
check_assist(
add_missing_match_arms,
r#"
enum E { A, B, C }
fn main() {
use E::*;
match (A, B, C)$0 {
(A | B , A, A | B | C) => (),
(A | B | C , B | C, A | B | C) => (),
}
}
"#,
r#"
enum E { A, B, C }
fn main() {
use E::*;
match (A, B, C) {
(A | B , A, A | B | C) => (),
(A | B | C , B | C, A | B | C) => (),
$0(C, A, A) => todo!(),
(C, A, B) => todo!(),
(C, A, C) => todo!(),
}
}
"#,
)
} }
#[test] #[test]