rust-lang / rust-lang/reference

Macros-by-example `expr` metavariable substitution behaves as if parenthesized

Open
#1,372 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macros
Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

While reviewing some code, I saw a macro-by-example using a metavariable of type expr in such a way that the code would be wrong if an expression were given to the macro that needed to be parenthesized — so I thought. Testing in the Playground, I found that substituted expressions appeared to be parenthesized automatically. I checked the Reference's section on macros-by-example and saw nothing about this; I looked at the Book's section on macros-by-example and saw nothing about this, but the Book suggested for further reading https://veykril.github.io/tlborm/, which explains that expressions are substituted as AST nodes rather than as tokens and so behave as if parenthesized. I suggest that this be mentioned in the Reference.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Reference's macros-by-example section and compare its treatment of expr metavariables with the linked Book and TLBORM explanations. Add a note explaining that substituted expressions behave as if parenthesized because they are substituted as AST nodes, and consider the documentation complete when this behavior is described clearly in the Reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.