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.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust

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.

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:

Dominant language
Rust
Stars
1.6k
Forks
607
Avg merge
1d 1h
Merged PRs (30d)
12

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.

More from rust-lang/reference

All issues in rust-lang/reference

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.