Skip to content

Commit

Permalink
Merge pull request #1543 from dtolnay/unarygroup
Browse files Browse the repository at this point in the history
Respect None-delimited group when parsing unary expr
  • Loading branch information
dtolnay authored Dec 11, 2023
2 parents 1c54651 + 1ffbda9 commit 5693152
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 5693152

Please sign in to comment.