Repository navigation
False positive local ambiguity in macro #154594
Copy link
Copy link
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
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):
- macro_rules: Fragment
vissomehow matches token[despite no visibility modifier starting with/having such token #128915 - meta matches pseudo-identifiers #59881
- PR macro_rules:
NtLifetimecannot start with an identifier #70768 - PR Enable fall through past $:lifetime matcher #51480
- PR Only match a fragment specifier if it starts with certain tokens. #42913
- Commit fc60797
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
Activity