rust-lang / rust-lang/reference
Document how tokens are compared in declarative macros
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
I wondered whether something like this would compile:
macro_rules! foo {
( r###"hello"### ) => {}; // 3 #-es
}
foo!( r##"hello"## ); // 2 #-es
It appears it does not, but this is not documented on the reference chapter about Macros By Example. There should be a section explaining the exact rules by which tokens are compared; there may be existing code out there that relies on behavior like this. Other examples I can think of:
- Doc comment tokens in matchers are currently ignored.
- Raw idents do not match non-raw idents (and vice versa).
- Suffixed literals do not match unsuffixed literals (and vice versa).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Rust Reference chapter on Macros By Example and inspect the linked rustc_expand/src/mbe/macro_parser.rs location. Trace the documented and implementation behavior for raw strings, doc comments, raw identifiers, and suffixed literals, then add a section explaining token comparison with examples. Done means the relevant matching rules and the reported raw-string case are clearly covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100