diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-23 16:41:46 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-23 16:41:46 +0000 |
commit | eff1b3fe4d17dcecf0ec9a30c35d6c88715cb8ea (patch) | |
tree | 7f5abbc9336a3476de08d8ee5c3284b8d41db72d /crates/ra_syntax | |
parent | b605271d7f3fa3fd3ac4dd0e1520b80b5fb13b40 (diff) | |
parent | bc48c9d5116f08efea26da94c82a3eaa1622fc5d (diff) |
Merge #3689
3689: implement fill match arm assist for tuple of enums r=matklad a=JoshMcguigan
This updates the fill match arm assist to work in cases where the user is matching on a tuple of enums.
Note, for now this does not apply when some match arms exist (other than the trivial `_`), but I think this could be added in the future.
I think this also lays the groundwork for filling match arms when matching on tuples of non-enum values, for example a tuple of an enum and a boolean.
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 9f6f1cc53..9257ccd1a 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -136,6 +136,20 @@ pub fn placeholder_pat() -> ast::PlaceholderPat { | |||
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | /// Creates a tuple of patterns from an interator of patterns. | ||
140 | /// | ||
141 | /// Invariant: `pats` must be length > 1 | ||
142 | /// | ||
143 | /// FIXME handle `pats` length == 1 | ||
144 | pub fn tuple_pat(pats: impl IntoIterator<Item = ast::Pat>) -> ast::TuplePat { | ||
145 | let pats_str = pats.into_iter().map(|p| p.to_string()).join(", "); | ||
146 | return from_text(&format!("({})", pats_str)); | ||
147 | |||
148 | fn from_text(text: &str) -> ast::TuplePat { | ||
149 | ast_from_text(&format!("fn f({}: ())", text)) | ||
150 | } | ||
151 | } | ||
152 | |||
139 | pub fn tuple_struct_pat( | 153 | pub fn tuple_struct_pat( |
140 | path: ast::Path, | 154 | path: ast::Path, |
141 | pats: impl IntoIterator<Item = ast::Pat>, | 155 | pats: impl IntoIterator<Item = ast::Pat>, |