Skip to content

Commit

Permalink
Merge pull request #716 from 8BitMate/master
Browse files Browse the repository at this point in the history
Parse TypeTuple with one element now requires trailing comma
  • Loading branch information
dtolnay committed Nov 8, 2019
2 parents a938fcd + 2af11a5 commit 11090bc
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/ty.rs
Expand Up @@ -784,9 +784,27 @@ pub mod parsing {
impl Parse for TypeTuple {
fn parse(input: ParseStream) -> Result<Self> {
let content;
let paren_token = parenthesized!(content in input);

if content.is_empty() {
return Ok(TypeTuple {
paren_token,
elems: Punctuated::new(),
});
}

let first: Type = content.parse()?;
Ok(TypeTuple {
paren_token: parenthesized!(content in input),
elems: content.parse_terminated(Type::parse)?,
paren_token,
elems: {
let mut elems = Punctuated::new();
elems.push_value(first);
elems.push_punct(content.parse()?);
let rest: Punctuated<Type, Token![,]> =
content.parse_terminated(Parse::parse)?;
elems.extend(rest);
elems
},
})
}
}
Expand Down

0 comments on commit 11090bc

Please sign in to comment.