Merge pull request #842 from dtolnay/group

Parse Expr::Struct containing None-delimited ident name
This commit is contained in:
David Tolnay 2020-05-30 16:44:20 -07:00 committed by GitHub
commit 7a81558977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -1691,7 +1691,11 @@ pub(crate) mod parsing {
// interactions, as they are fully contained.
#[cfg(feature = "full")]
fn atom_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
if input.peek(token::Group) && !input.peek2(Token![::]) && !input.peek2(Token![!]) {
if input.peek(token::Group)
&& !input.peek2(Token![::])
&& !input.peek2(Token![!])
&& !input.peek2(token::Brace)
{
input.call(expr_group).map(Expr::Group)
} else if input.peek(Lit) {
input.parse().map(Expr::Lit)

View File

@ -142,3 +142,25 @@ fn test_macro_variable_macro() {
}
"###);
}
#[test]
fn test_macro_variable_struct() {
// mimics the token stream corresponding to `$struct {}`
let tokens = TokenStream::from_iter(vec![
TokenTree::Group(Group::new(Delimiter::None, quote! { S })),
TokenTree::Group(Group::new(Delimiter::Brace, TokenStream::new())),
]);
snapshot!(tokens as Expr, @r###"
Expr::Struct {
path: Path {
segments: [
PathSegment {
ident: "S",
arguments: None,
},
],
},
}
"###);
}