Skip to content

Make the missing-const-type suggestion deterministic under the parallel front-end#157341

Open
xmakro wants to merge 2 commits into
rust-lang:mainfrom
xmakro:fix/parallel-item-no-type
Open

Make the missing-const-type suggestion deterministic under the parallel front-end#157341
xmakro wants to merge 2 commits into
rust-lang:mainfrom
xmakro:fix/parallel-item-no-type

Conversation

@xmakro
Copy link
Copy Markdown

@xmakro xmakro commented Jun 2, 2026

Part of #154314. Addresses the "different infer type: bool" row.

tests/ui/consts/const-item-no-type/in-macro.rs was marked //@ ignore-parallel-frontend different infer type: bool. The test has a macro that expands to two const A = ...; items, one whose body infers usize and one whose body infers bool. Both items lack a type, so the parser stashes an ItemNoType diagnostic for each, intending typeck to fill in the inferred type as a suggestion.

The two items come from one macro repetition, so they share the same empty span. Stash slots are keyed by span, so the second stash overwrites the first and only one slot survives. Two type_of queries then race to steal it. The winner emits missing type for const item with the type it inferred for its own item, and the loser emits the generic missing type for item. Single threaded the first item always wins, but under the parallel front-end the winner is nondeterministic, so the suggested type flips between : usize and : bool from run to run.

The steal-failure arm already drops the suggestion for macro-expanded items, with a comment that the suggestion is invalid because it cannot be applied to the expansion. This makes the steal-success arm do the same, so the suggestion no longer appears for macro-expanded items and the output is stable. The only diagnostic change is that the provide a type for the constant suggestion is no longer shown when the item comes from a macro expansion, which is the same case the other arm already suppresses.

With that the test is re-enabled. It passes single threaded and under --parallel-frontend-threads=16 --iteration-count=300 --force-rerun. The wider consts, suggestions, typeck, and static test directories pass unchanged.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 2, 2026
xmakro added 2 commits June 2, 2026 17:54
…el front-end

When a macro expands to several items that lack a type, such as two
`const A = ...;` produced by one repetition, the items all share the same
empty span. The parser stashes one `ItemNoType` diagnostic per item, but
stash slots are keyed by span, so only one survives and a single
`type_of` query steals it. That query fills the suggestion in with the
type it inferred for its own item, and under the parallel front-end which
query wins the steal is nondeterministic, so the suggested type changes
from run to run.

The steal-failure arm already omits the suggestion for macro-expanded
items because it cannot be applied to the expansion. Do the same in the
steal-success arm so the output no longer depends on the race.
The missing-const-type suggestion is now deterministic, so this test no
longer needs to be ignored under the parallel front-end.
@xmakro xmakro force-pushed the fix/parallel-item-no-type branch from aea21fe to 36104a6 Compare June 3, 2026 00:54
@xmakro xmakro marked this pull request as ready for review June 3, 2026 00:55
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 3, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 3, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 3, 2026

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (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
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 73 candidates
  • Random selection from 18 candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants