Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #13945 - bvanjoi:orpat-match, r=lnicola
fix: check orpat in missing match fixed #13942
bors 2023-01-14
parent 8800ea6 · parent e9724e5 · commit ce86f12
-rw-r--r--crates/ide-assists/src/handlers/add_missing_match_arms.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/crates/ide-assists/src/handlers/add_missing_match_arms.rs
index 8e4ac69ae6..0461cc790e 100644
--- a/crates/ide-assists/src/handlers/add_missing_match_arms.rs
+++ b/crates/ide-assists/src/handlers/add_missing_match_arms.rs
@@ -269,6 +269,7 @@ fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool {
(Pat::TuplePat(tpat), Pat::TuplePat(tvar)) => {
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),
}
}
@@ -526,6 +527,19 @@ fn foo(a: bool) {
r#"
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 {
(true, true) => {}
(true, false) => {}
(false, true) => {}
@@ -566,6 +580,26 @@ fn foo(a: bool) {
r#"
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 {
(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]