diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-16 16:47:43 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-16 16:47:43 +0100 |
commit | e53919a425bf062056a23e825fb30a51a639385c (patch) | |
tree | 6b3007c5fc560bed5b7b857d865e8c84d58c2fc0 /crates/ide_assists/src | |
parent | 75371eb0fa015ba8834ae2b66cda68eba5d83874 (diff) | |
parent | 8965be3d0e5162c8a39c5ba1fd074740ac732566 (diff) |
Merge #8543
8543: Assist fix: Fill match arms for a tuple of a single enum. r=Veykril a=iDawer
This is rather a small fix addressing an issue mentioned in https://github.com/rust-analyzer/rust-analyzer/issues/8493#issuecomment-818770670
Co-authored-by: Dawer <[email protected]>
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r-- | crates/ide_assists/src/handlers/fill_match_arms.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/crates/ide_assists/src/handlers/fill_match_arms.rs b/crates/ide_assists/src/handlers/fill_match_arms.rs index 878b3a3fa..80bd1b7e8 100644 --- a/crates/ide_assists/src/handlers/fill_match_arms.rs +++ b/crates/ide_assists/src/handlers/fill_match_arms.rs | |||
@@ -71,12 +71,6 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
71 | return None; | 71 | return None; |
72 | } | 72 | } |
73 | 73 | ||
74 | // We do not currently support filling match arms for a tuple | ||
75 | // containing a single enum. | ||
76 | if enum_defs.len() < 2 { | ||
77 | return None; | ||
78 | } | ||
79 | |||
80 | // When calculating the match arms for a tuple of enums, we want | 74 | // When calculating the match arms for a tuple of enums, we want |
81 | // to create a match arm for each possible combination of enum | 75 | // to create a match arm for each possible combination of enum |
82 | // values. The `multi_cartesian_product` method transforms | 76 | // values. The `multi_cartesian_product` method transforms |
@@ -514,10 +508,7 @@ fn main() { | |||
514 | 508 | ||
515 | #[test] | 509 | #[test] |
516 | fn fill_match_arms_single_element_tuple_of_enum() { | 510 | fn fill_match_arms_single_element_tuple_of_enum() { |
517 | // For now we don't hande the case of a single element tuple, but | 511 | check_assist( |
518 | // we could handle this in the future if `make::tuple_pat` allowed | ||
519 | // creating a tuple with a single pattern. | ||
520 | check_assist_not_applicable( | ||
521 | fill_match_arms, | 512 | fill_match_arms, |
522 | r#" | 513 | r#" |
523 | enum A { One, Two } | 514 | enum A { One, Two } |
@@ -528,6 +519,17 @@ fn main() { | |||
528 | } | 519 | } |
529 | } | 520 | } |
530 | "#, | 521 | "#, |
522 | r#" | ||
523 | enum A { One, Two } | ||
524 | |||
525 | fn main() { | ||
526 | let a = A::One; | ||
527 | match (a, ) { | ||
528 | $0(A::One,) => {} | ||
529 | (A::Two,) => {} | ||
530 | } | ||
531 | } | ||
532 | "#, | ||
531 | ); | 533 | ); |
532 | } | 534 | } |
533 | 535 | ||