Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect None-delimited group when parsing unary expr #1543

Merged
merged 2 commits into from Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/expr.rs
Expand Up @@ -1368,6 +1368,10 @@ pub(crate) mod parsing {
fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
let begin = input.fork();
let attrs = input.call(expr_attrs)?;
if input.peek(token::Group) {
return trailer_expr(begin, attrs, input, allow_struct);
}

if input.peek(Token![&]) {
let and_token: Token![&] = input.parse()?;
let raw: Option<kw::raw> = if input.peek(kw::raw)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_expr.rs
Expand Up @@ -216,6 +216,31 @@ fn test_macro_variable_struct() {
"###);
}

#[test]
fn test_macro_variable_unary() {
// mimics the token stream corresponding to `$expr.method()` where expr is `&self`
let inner = Group::new(Delimiter::None, quote!(&self));
let tokens = quote!(#inner.method());
snapshot!(tokens as Expr, @r###"
Expr::MethodCall {
receiver: Expr::Group {
expr: Expr::Reference {
expr: Expr::Path {
path: Path {
segments: [
PathSegment {
ident: "self",
},
],
},
},
},
},
method: "method",
}
"###);
}

#[test]
fn test_macro_variable_match_arm() {
// mimics the token stream corresponding to `match v { _ => $expr }`
Expand Down