Skip to content

False positive local ambiguity in macro #154594

Open

Description

@Clipi-12

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:

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions