False positive `local ambiguity` in macro
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
MCVE:
macro_rules! mcve {
($($my_lft:lifetime)? $($my_ty:ty)?) => {};
}
mcve!('a);
error: local ambiguity when calling macro `mcve`: multiple parsing options: built-in NTs lifetime ('my_lft') or ty ('my_ty').
--> src/lib.rs:5:7
|
5 | mcve!('a);
| ^^
This piece of code should only be able to match $my_lft, but it complains about being able to reach $my_ty.
To prove that $my_ty cannot be reached, and that this problem happens with lifetime but not with other types such as block, i created the following playground link:
- https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=837c3d88bb5f00ad8936e3ede274f8f2
- (gist) https://gist.github.com/rust-play/837c3d88bb5f00ad8936e3ede274f8f2
Meta
Tried it in editions 2024, 2021 and 2018, using nightly, 1.94.1, 1.80.1, 1.70.0, 1.60.0, 1.50.0, 1.40.0 and 1.31.0 (i.e. the first version with edition 2018, where the $(...)? operator wasn't even stable).
Similar issues (some probably too old to be relevant, but still included just in case):
- https://github.com/rust-lang/rust/issues/128915
- https://github.com/rust-lang/rust/issues/59881
- PR https://github.com/rust-lang/rust/pull/70768
- PR https://github.com/rust-lang/rust/pull/51480
- PR https://github.com/rust-lang/rust/pull/42913
- Commit https://github.com/rust-lang/rust/commit/fc60797f7f3079288bdd1717dedbb885eaf1dbfa
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 by reproducing the MCVE in the linked Rust Playground and compare the lifetime case with the block case. Trace macro parsing behavior for the optional lifetime and type metavariables, then verify that the reported local ambiguity disappears without changing valid ambiguity diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100