rust-lang / rust-lang/reference

Document how tokens are compared in declarative macros

Open
#2,315 2 comments 0 reactions 0 assignees View on GitHub

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:

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.