diff --git a/src/expr.rs b/src/expr.rs index f3e37d49c7..334caada90 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1368,6 +1368,10 @@ pub(crate) mod parsing { fn unary_expr(input: ParseStream, allow_struct: AllowStruct) -> Result { 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 = if input.peek(kw::raw) diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 9d0b44f9ba..64cbea88f7 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -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 }`