Skip to content

Make the ordering of non-terminal binds in ambiguity error messages deterministic#158894

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
bal-e:ambiguity-nt-ordering
Jul 9, 2026
Merged

Make the ordering of non-terminal binds in ambiguity error messages deterministic#158894
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
bal-e:ambiguity-nt-ordering

Conversation

@bal-e

@bal-e bal-e commented Jul 7, 2026

Copy link
Copy Markdown

My next PR will rework macro parsing to use a DFS approach instead of a BFS. It will change the order in which the parsing space is explored, and while this does not change the behavior of parsing in success cases, it did cause changes to some error messages; in particular, when an ambiguity error occurs, it would sometimes report non-terminal binds in a different order (e.g. in error: local ambiguity when calling macro `foo`: multiple parsing options: built-in NTs ident ('i') or ident ('j').). I realized that the current macro parsing code does not enforce a particular order for those binds, so this PR 1) adds a test case for strange bind orderings and 2) makes the bind ordering deterministic (in line with the ordering of those binds in the macro definition, which was how binds tended to be ordered anyway).

Ideally reviewed commit-by-commit.

r? @nnethercote

arya dradjica added 2 commits July 3, 2026 09:29
None of the existing tests captured a case where non-terminal binds
appeared differently ordered than their definition in their rule, so I
wrote a test for it.

The existing macro parsing code is quite resilient to this kind of
mis-ordering; it took quite a convoluted macro to trigger a case where
the ordering is incorrect today. I've documented the parse tree (based
on my own mental model) that the convoluted macro causes.
The order of `bb_mps` and `next_mps` depends on arbitrary implementation
choices, e.g. the order in which `$(a)? b` causes `a b` and `b` to be
explored. To stop depending on these implementation details, this commit
sorts `bb_mps` and `next_mps` by `mp.idx` (corresponding to the position
in the rule) before presenting error messages.

This makes it easier to refactor the macro parsing implementation.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 7, 2026
@rustbot

rustbot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @nnethercote (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@nnethercote nnethercote left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for breaking up the commits and the detailed commit messages and comments, it makes reviewing really easy.

View changes since this review

@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 87c76f9 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 8, 2026
…thercote

Make the ordering of non-terminal binds in ambiguity error messages deterministic

My next PR will rework macro parsing to use a DFS approach instead of a BFS. It will change the order in which the parsing space is explored, and while this does not change the behavior of parsing in success cases, it did cause changes to some error messages; in particular, when an ambiguity error occurs, it would sometimes report non-terminal binds in a different order (e.g. in ```error: local ambiguity when calling macro `foo`: multiple parsing options: built-in NTs ident ('i') or ident ('j').```). I realized that the current macro parsing code does not enforce a particular order for those binds, so this PR 1) adds a test case for strange bind orderings and 2) makes the bind ordering deterministic (in line with the ordering of those binds in the macro definition, which was how binds tended to be ordered anyway).

Ideally reviewed commit-by-commit.

r? @nnethercote
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…thercote

Make the ordering of non-terminal binds in ambiguity error messages deterministic

My next PR will rework macro parsing to use a DFS approach instead of a BFS. It will change the order in which the parsing space is explored, and while this does not change the behavior of parsing in success cases, it did cause changes to some error messages; in particular, when an ambiguity error occurs, it would sometimes report non-terminal binds in a different order (e.g. in ```error: local ambiguity when calling macro `foo`: multiple parsing options: built-in NTs ident ('i') or ident ('j').```). I realized that the current macro parsing code does not enforce a particular order for those binds, so this PR 1) adds a test case for strange bind orderings and 2) makes the bind ordering deterministic (in line with the ordering of those binds in the macro definition, which was how binds tended to be ordered anyway).

Ideally reviewed commit-by-commit.

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158951 (Merge three `MaxUniverse`s into one)
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158951 (Merge three `MaxUniverse`s into one)
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158951 (Merge three `MaxUniverse`s into one)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 9, 2026
…thercote

Make the ordering of non-terminal binds in ambiguity error messages deterministic

My next PR will rework macro parsing to use a DFS approach instead of a BFS. It will change the order in which the parsing space is explored, and while this does not change the behavior of parsing in success cases, it did cause changes to some error messages; in particular, when an ambiguity error occurs, it would sometimes report non-terminal binds in a different order (e.g. in ```error: local ambiguity when calling macro `foo`: multiple parsing options: built-in NTs ident ('i') or ident ('j').```). I realized that the current macro parsing code does not enforce a particular order for those binds, so this PR 1) adds a test case for strange bind orderings and 2) makes the bind ordering deterministic (in line with the ordering of those binds in the macro definition, which was how binds tended to be ordered anyway).

Ideally reviewed commit-by-commit.

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
Rollup of 23 pull requests

Successful merges:

 - #158968 (stdarch subtree update)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158870 (std: merge the unix-like io::error modules into one file)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156144 (Better docs for PartialEq (includes macro rename))
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #157995 (`Vec::dedup_by` docs explicit function argument order)
 - #158307 (CI job for parallel frontend ui tests)
 - #158741 (Simplify `Option::into_flat_iter` signature)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158978 (Add regression test for too-big by-value ABI args)
@rust-bors
rust-bors Bot merged commit 2bb944e into rust-lang:main Jul 9, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 9, 2026
rust-timer added a commit that referenced this pull request Jul 9, 2026
Rollup merge of #158894 - bal-e:ambiguity-nt-ordering, r=nnethercote

Make the ordering of non-terminal binds in ambiguity error messages deterministic

My next PR will rework macro parsing to use a DFS approach instead of a BFS. It will change the order in which the parsing space is explored, and while this does not change the behavior of parsing in success cases, it did cause changes to some error messages; in particular, when an ambiguity error occurs, it would sometimes report non-terminal binds in a different order (e.g. in ```error: local ambiguity when calling macro `foo`: multiple parsing options: built-in NTs ident ('i') or ident ('j').```). I realized that the current macro parsing code does not enforce a particular order for those binds, so this PR 1) adds a test case for strange bind orderings and 2) makes the bind ordering deterministic (in line with the ordering of those binds in the macro definition, which was how binds tended to be ordered anyway).

Ideally reviewed commit-by-commit.

r? @nnethercote
@bal-e
bal-e deleted the ambiguity-nt-ordering branch July 9, 2026 13:33
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 10, 2026
Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#158968 (stdarch subtree update)
 - rust-lang/rust#154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - rust-lang/rust#158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - rust-lang/rust#158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - rust-lang/rust#158870 (std: merge the unix-like io::error modules into one file)
 - rust-lang/rust#158920 (Update wasm-component-ld to 0.5.26)
 - rust-lang/rust#158926 (wrapping_sh* methods: clarify underspecified reference)
 - rust-lang/rust#158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - rust-lang/rust#158932 (Do not build the compiler when invoking `x perf compare`)
 - rust-lang/rust#158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - rust-lang/rust#151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - rust-lang/rust#156144 (Better docs for PartialEq (includes macro rename))
 - rust-lang/rust#156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - rust-lang/rust#157995 (`Vec::dedup_by` docs explicit function argument order)
 - rust-lang/rust#158307 (CI job for parallel frontend ui tests)
 - rust-lang/rust#158741 (Simplify `Option::into_flat_iter` signature)
 - rust-lang/rust#158807 (Add regression test for CString::clone_into unwind safety)
 - rust-lang/rust#158862 (Fix the span for parameter suggestion )
 - rust-lang/rust#158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - rust-lang/rust#158902 (add codegen test for range length bound propagation)
 - rust-lang/rust#158913 (Update `browser-ui-test` version to `0.24.1`)
 - rust-lang/rust#158935 (std: support real fd methods on Emscripten)
 - rust-lang/rust#158978 (Add regression test for too-big by-value ABI args)
rust-bors Bot pushed a commit that referenced this pull request Jul 11, 2026
Preparatory changes for macro parsing BFS->DFS

This PR contains some miscellaneous commits I accumulated while working on the BFS->DFS change. Their goal is to simplify the code and clarifying existing behavior. It is a conceptual follow-up to #158577. High-level overview:

- Adds context about the current match arm to `Tracker` through the new `Tracker::prepare()`, so that the `WhichMatcher` parameter is available implicitly. In a later PR, this will be used to reference `MatcherLoc`s by index.

- Reformulates matching failures to work more like ambiguity errors wrt. `Tracker`; `Tracker::build_failure()` (which would build a failure consumed by `Tracker::after_arm()`) becomes `Tracker::failure()` which eagerly processes the error. This removes the need for `ParseResult::Failure` to store any data at all. This relies on the match arm context provided by `Tracker::prepare()`.

- There is a subtle edge case involving `token::Eof` and non-terminal parsing; `Parser::nonterminal_may_begin_with()` would sometimes return `true` for `token::Eof`, even though the non-terminal parse would never be attempted. `TtParser` did not check `bb_mps` when handling `token::Eof`, so non-terminal parses at EOF were being silently dropped. I changed `Parser::nonterminal_may_begin_with()` to always return `false` for `token::Eof`, making this behavior much more visible. I added a test case to make sure meta-variables return the same error uniformly when parsed against EOF.

Contains #158894, which should be merged soon (after which I'll rebase onto `main`).

Best reviewed commit-by-commit.

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Jul 11, 2026
Preparatory changes for macro parsing BFS->DFS

This PR contains some miscellaneous commits I accumulated while working on the BFS->DFS change. Their goal is to simplify the code and clarifying existing behavior. It is a conceptual follow-up to #158577. High-level overview:

- Adds context about the current match arm to `Tracker` through the new `Tracker::prepare()`, so that the `WhichMatcher` parameter is available implicitly. In a later PR, this will be used to reference `MatcherLoc`s by index.

- Reformulates matching failures to work more like ambiguity errors wrt. `Tracker`; `Tracker::build_failure()` (which would build a failure consumed by `Tracker::after_arm()`) becomes `Tracker::failure()` which eagerly processes the error. This removes the need for `ParseResult::Failure` to store any data at all. This relies on the match arm context provided by `Tracker::prepare()`.

- There is a subtle edge case involving `token::Eof` and non-terminal parsing; `Parser::nonterminal_may_begin_with()` would sometimes return `true` for `token::Eof`, even though the non-terminal parse would never be attempted. `TtParser` did not check `bb_mps` when handling `token::Eof`, so non-terminal parses at EOF were being silently dropped. I changed `Parser::nonterminal_may_begin_with()` to always return `false` for `token::Eof`, making this behavior much more visible. I added a test case to make sure meta-variables return the same error uniformly when parsed against EOF.

Contains #158894, which should be merged soon (after which I'll rebase onto `main`).

Best reviewed commit-by-commit.

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Jul 12, 2026
Preparatory changes for macro parsing BFS->DFS



This PR contains some miscellaneous commits I accumulated while working on the BFS->DFS change. Their goal is to simplify the code and clarifying existing behavior. It is a conceptual follow-up to #158577. High-level overview:

- Adds context about the current match arm to `Tracker` through the new `Tracker::prepare()`, so that the `WhichMatcher` parameter is available implicitly. In a later PR, this will be used to reference `MatcherLoc`s by index.

- Reformulates matching failures to work more like ambiguity errors wrt. `Tracker`; `Tracker::build_failure()` (which would build a failure consumed by `Tracker::after_arm()`) becomes `Tracker::failure()` which eagerly processes the error. This removes the need for `ParseResult::Failure` to store any data at all. This relies on the match arm context provided by `Tracker::prepare()`.

- There is a subtle edge case involving `token::Eof` and non-terminal parsing; `Parser::nonterminal_may_begin_with()` would sometimes return `true` for `token::Eof`, even though the non-terminal parse would never be attempted. `TtParser` did not check `bb_mps` when handling `token::Eof`, so non-terminal parses at EOF were being silently dropped. I changed `Parser::nonterminal_may_begin_with()` to always return `false` for `token::Eof`, making this behavior much more visible. I added a test case to make sure meta-variables return the same error uniformly when parsed against EOF.

Contains #158894, which should be merged soon (after which I'll rebase onto `main`).

Best reviewed commit-by-commit.

r? @nnethercote
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Jul 13, 2026
Preparatory changes for macro parsing BFS->DFS



This PR contains some miscellaneous commits I accumulated while working on the BFS->DFS change. Their goal is to simplify the code and clarifying existing behavior. It is a conceptual follow-up to rust-lang/rust#158577. High-level overview:

- Adds context about the current match arm to `Tracker` through the new `Tracker::prepare()`, so that the `WhichMatcher` parameter is available implicitly. In a later PR, this will be used to reference `MatcherLoc`s by index.

- Reformulates matching failures to work more like ambiguity errors wrt. `Tracker`; `Tracker::build_failure()` (which would build a failure consumed by `Tracker::after_arm()`) becomes `Tracker::failure()` which eagerly processes the error. This removes the need for `ParseResult::Failure` to store any data at all. This relies on the match arm context provided by `Tracker::prepare()`.

- There is a subtle edge case involving `token::Eof` and non-terminal parsing; `Parser::nonterminal_may_begin_with()` would sometimes return `true` for `token::Eof`, even though the non-terminal parse would never be attempted. `TtParser` did not check `bb_mps` when handling `token::Eof`, so non-terminal parses at EOF were being silently dropped. I changed `Parser::nonterminal_may_begin_with()` to always return `false` for `token::Eof`, making this behavior much more visible. I added a test case to make sure meta-variables return the same error uniformly when parsed against EOF.

Contains rust-lang/rust#158894, which should be merged soon (after which I'll rebase onto `main`).

Best reviewed commit-by-commit.

r? @nnethercote
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
Eagerly check for ambiguity in macro parsing

This PR implements an important step leading up to the BFS->DFS change: it makes ambiguity detection (as occurs when parsing meta-variables and reaching EOF) eager. Rather than accumulating the `bb_mps` and `eof_mps` lists, then checking that a single valid parse exists, this PR introduces a `check_for_ambiguity()` method that gets called as soon as the relevant `MatcherLoc` is observed. `check_for_ambiguity()` immediately drains `cur_mps` instead of waiting for the outer loop to do so, and evaluates the mps within a "checking for ambiguity" context.

This change was complicated by the fact that `bb_mps` was relied on for error messages; it was passed along to `Tracker::ambiguity()`. The same is true for `next_mps`. The first few commits of this PR (after pending rebases) add state to `Tracker` so that it can compute the relevant diagnostic information independently of `bb_mps`.

This PR complicates the control flow around `parse_tt_inner()` in subtle ways. I'm not super happy about it, but I think it will become easier to understand again once a DFS approach is implemented.

~This PR contains #158894 and #158974. I'll rebase on top of `main` once they're both merged.~

Best reviewed commit-by-commit.

r? @nnethercote
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Jul 15, 2026
Eagerly check for ambiguity in macro parsing

This PR implements an important step leading up to the BFS->DFS change: it makes ambiguity detection (as occurs when parsing meta-variables and reaching EOF) eager. Rather than accumulating the `bb_mps` and `eof_mps` lists, then checking that a single valid parse exists, this PR introduces a `check_for_ambiguity()` method that gets called as soon as the relevant `MatcherLoc` is observed. `check_for_ambiguity()` immediately drains `cur_mps` instead of waiting for the outer loop to do so, and evaluates the mps within a "checking for ambiguity" context.

This change was complicated by the fact that `bb_mps` was relied on for error messages; it was passed along to `Tracker::ambiguity()`. The same is true for `next_mps`. The first few commits of this PR (after pending rebases) add state to `Tracker` so that it can compute the relevant diagnostic information independently of `bb_mps`.

This PR complicates the control flow around `parse_tt_inner()` in subtle ways. I'm not super happy about it, but I think it will become easier to understand again once a DFS approach is implemented.

~This PR contains rust-lang/rust#158894 and rust-lang/rust#158974. I'll rebase on top of `main` once they're both merged.~

Best reviewed commit-by-commit.

r? @nnethercote
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jul 16, 2026
Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#158968 (stdarch subtree update)
 - rust-lang/rust#154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - rust-lang/rust#158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - rust-lang/rust#158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - rust-lang/rust#158870 (std: merge the unix-like io::error modules into one file)
 - rust-lang/rust#158920 (Update wasm-component-ld to 0.5.26)
 - rust-lang/rust#158926 (wrapping_sh* methods: clarify underspecified reference)
 - rust-lang/rust#158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - rust-lang/rust#158932 (Do not build the compiler when invoking `x perf compare`)
 - rust-lang/rust#158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - rust-lang/rust#151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - rust-lang/rust#156144 (Better docs for PartialEq (includes macro rename))
 - rust-lang/rust#156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - rust-lang/rust#157995 (`Vec::dedup_by` docs explicit function argument order)
 - rust-lang/rust#158307 (CI job for parallel frontend ui tests)
 - rust-lang/rust#158741 (Simplify `Option::into_flat_iter` signature)
 - rust-lang/rust#158807 (Add regression test for CString::clone_into unwind safety)
 - rust-lang/rust#158862 (Fix the span for parameter suggestion )
 - rust-lang/rust#158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - rust-lang/rust#158902 (add codegen test for range length bound propagation)
 - rust-lang/rust#158913 (Update `browser-ui-test` version to `0.24.1`)
 - rust-lang/rust#158935 (std: support real fd methods on Emscripten)
 - rust-lang/rust#158978 (Add regression test for too-big by-value ABI args)
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jul 16, 2026
Eagerly check for ambiguity in macro parsing

This PR implements an important step leading up to the BFS->DFS change: it makes ambiguity detection (as occurs when parsing meta-variables and reaching EOF) eager. Rather than accumulating the `bb_mps` and `eof_mps` lists, then checking that a single valid parse exists, this PR introduces a `check_for_ambiguity()` method that gets called as soon as the relevant `MatcherLoc` is observed. `check_for_ambiguity()` immediately drains `cur_mps` instead of waiting for the outer loop to do so, and evaluates the mps within a "checking for ambiguity" context.

This change was complicated by the fact that `bb_mps` was relied on for error messages; it was passed along to `Tracker::ambiguity()`. The same is true for `next_mps`. The first few commits of this PR (after pending rebases) add state to `Tracker` so that it can compute the relevant diagnostic information independently of `bb_mps`.

This PR complicates the control flow around `parse_tt_inner()` in subtle ways. I'm not super happy about it, but I think it will become easier to understand again once a DFS approach is implemented.

~This PR contains rust-lang/rust#158894 and rust-lang/rust#158974. I'll rebase on top of `main` once they're both merged.~

Best reviewed commit-by-commit.

r? @nnethercote
Kobzol pushed a commit to Kobzol/rustc_codegen_cranelift that referenced this pull request Jul 23, 2026
Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#158968 (stdarch subtree update)
 - rust-lang/rust#154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - rust-lang/rust#158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - rust-lang/rust#158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - rust-lang/rust#158870 (std: merge the unix-like io::error modules into one file)
 - rust-lang/rust#158920 (Update wasm-component-ld to 0.5.26)
 - rust-lang/rust#158926 (wrapping_sh* methods: clarify underspecified reference)
 - rust-lang/rust#158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - rust-lang/rust#158932 (Do not build the compiler when invoking `x perf compare`)
 - rust-lang/rust#158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - rust-lang/rust#151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - rust-lang/rust#156144 (Better docs for PartialEq (includes macro rename))
 - rust-lang/rust#156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - rust-lang/rust#157995 (`Vec::dedup_by` docs explicit function argument order)
 - rust-lang/rust#158307 (CI job for parallel frontend ui tests)
 - rust-lang/rust#158741 (Simplify `Option::into_flat_iter` signature)
 - rust-lang/rust#158807 (Add regression test for CString::clone_into unwind safety)
 - rust-lang/rust#158862 (Fix the span for parameter suggestion )
 - rust-lang/rust#158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - rust-lang/rust#158902 (add codegen test for range length bound propagation)
 - rust-lang/rust#158913 (Update `browser-ui-test` version to `0.24.1`)
 - rust-lang/rust#158935 (std: support real fd methods on Emscripten)
 - rust-lang/rust#158978 (Add regression test for too-big by-value ABI args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants