From 8965be3d0e5162c8a39c5ba1fd074740ac732566 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Fri, 16 Apr 2021 17:22:11 +0500 Subject: Fill match arms for a tuple of a single enum. --- crates/syntax/src/ast/make.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'crates/syntax/src') diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index c6a7b99b7..94d4f2cf0 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs @@ -29,9 +29,13 @@ pub fn ty(text: &str) -> ast::Type { pub fn ty_unit() -> ast::Type { ty("()") } -// FIXME: handle types of length == 1 pub fn ty_tuple(types: impl IntoIterator) -> ast::Type { - let contents = types.into_iter().join(", "); + let mut count: usize = 0; + let mut contents = types.into_iter().inspect(|_| count += 1).join(", "); + if count == 1 { + contents.push(','); + } + ty(&format!("({})", contents)) } // FIXME: handle path to type @@ -292,11 +296,13 @@ pub fn wildcard_pat() -> ast::WildcardPat { /// Creates a tuple of patterns from an iterator of patterns. /// -/// Invariant: `pats` must be length > 1 -/// -/// FIXME handle `pats` length == 1 +/// Invariant: `pats` must be length > 0 pub fn tuple_pat(pats: impl IntoIterator) -> ast::TuplePat { - let pats_str = pats.into_iter().map(|p| p.to_string()).join(", "); + let mut count: usize = 0; + let mut pats_str = pats.into_iter().inspect(|_| count += 1).join(", "); + if count == 1 { + pats_str.push(','); + } return from_text(&format!("({})", pats_str)); fn from_text(text: &str) -> ast::TuplePat { -- cgit v1.2.3