rust-lang / rust-lang/rustc-dev-guide
Ambiguous macro call
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 1.9k
- Forks
- 613
- Avg merge
- 17h 24m
- Merged PRs (30d)
- 39
Description
The guide says right here:
Error: some fatal error has occurred in the parser. For example, this happens if there are more than one pattern match, since that indicates the macro is ambiguous.
This seems not to be the case.
macro_rules! times {
(a b) => (5000);
($x:ident b) => ($x * $x);
($x:ident $y:ident) => ($x * $y);
}
fn main() {
dbg!(times!(a b));
}
Output: 5000
Rust just chooses the first pattern that matches. In fact, you can use the exact same pattern twice and the Rust compiler won't complain.
macro_rules! times {
(a b) => (5000);
(a b) => (10000);
}
fn main() {
dbg!(times!(a b));
}
Output: 5000
Am I misunderstanding the description or is the description wrong?
Contributor guide
No contributing guide indexed for this repository
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
Open src/macro-expansion.md at the linked passage and compare its claim about ambiguous macro patterns with the Rust examples in the issue. Check the relevant macro-matching behavior before revising the explanation. Done means the guide accurately describes which matching patterns are accepted and how Rust selects among them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100