Skip to content

Fix where clause parsing of type aliases & const items - #165256

Open
fmease wants to merge 6 commits into
rust-lang:mainfrom
fmease:parser-where-clauses-fixes
Open

fmease wants to merge 6 commits into
rust-lang:mainfrom
fmease:parser-where-clauses-fixes

Conversation

@fmease

@fmease fmease commented Oct 31, 2026 •

Copy link
Copy Markdown
Member
  1. Don't artificially reject duplicate (non-empty) where clauses on bodiless type aliases / associated types.
  2. Reject (literally) where where (i.e., duplicate empty where clauses) on const items (unstable feature generic_const_items). See commit for details.
  3. Tiny compiler & test cleanups that were necessary to soundly navigate these seas

Best reviewed commit by commit.

(No LLM was or will be used by me during the entire creation process of this PR)

@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 Oct 31, 2026
@rustbot

rustbot commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

r? @beetrees

rustbot has assigned @beetrees.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 22 candidates

@rust-log-analyzer

This comment has been minimized.

@fmease
fmease force-pushed the parser-where-clauses-fixes branch 4 times, most recently from 8425e6b to db5181f Compare October 31, 2026 22:05
@rust-log-analyzer

This comment has been minimized.

@fmease
fmease force-pushed the parser-where-clauses-fixes branch 2 times, most recently from ff47213 to 668b5c9 Compare October 31, 2026 22:58
@fmease fmease changed the title Fix where clause parsing for type aliases & const items Fix where clause parsing of type aliases & const items Nov 1, 2026
@rust-bors

This comment has been minimized.

@fmease
fmease force-pushed the parser-where-clauses-fixes branch from 668b5c9 to 3dbebfe Compare November 2, 2026 23:16
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease
fmease force-pushed the parser-where-clauses-fixes branch 2 times, most recently from ceccfbd to 724c67c Compare November 6, 2026 09:45
@rustbot

rustbot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@fmease
fmease force-pushed the parser-where-clauses-fixes branch 2 times, most recently from 588a7d9 to 082df29 Compare November 6, 2026 09:47
Previously they were separate because they each contained a fatal parse
error. However, by introducing "barrier functions" we give the parser
synchronization points to successfully recover from these syntax errors
allowing us to put both test cases into the same file.

We call the combined file `where-clause-predicates.rs` because it took me
a while to realize that this test mainly means to test where clause
predicates themselves and not *type aliases with where clauses*.
See also PR RUST-39158 which introduced these files and which is about
"bound parsing" in general.

This makes it alot clearer which UI tests actually concern where clauses
on type aliases *specifically* allowing me to more easily find an
existing test file I can extend with test cases covering "double where
clauses",
namely `tests/ui/where-clauses/where-clause-placement-type-alias.rs`.
There's no reason to return a large tuple that the caller then has to
convert into an `ItemKind`. None of the callers care about the concrete
fields.

In the case of `parse_const_item` it's likely a remnant of the time when
it was used to parse (or rather finish parsing) const (`ItemKind::Const`)
*and* static items (`ItemKind::Static`).
@fmease fmease mentioned this pull request Nov 12, 2026
1 of 7 tasks
@beetrees

beetrees commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Does this leads to any stable code not compiling when it does today? If so, does that need a FCP or is it ok given that it's essentially a bug fix?

r? @BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned beetrees Nov 13, 2026
@rustbot

rustbot commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@fmease

fmease commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

Does this leads to any stable code not compiling when it does today?

Precisely the opposite, it makes more code compile on stable. I consider it a bug fix that doesn't need an FCP because this code would've compiled if we hadn't introduced that overzealous parse error recovery in the linked PR (error recovery should obviously never influence / dictate syntax).

(As alluded to in the PR description (see the dates I posted), this was most likely missed because of incredibly unfortunate timing: The error recovery was added when type aliases couldn't have two where clauses yet and the PR extending type aliases was opened long before the error recovery was added but only merged a while after it, so this was most likely just missed during a rebase)

@fmease

fmease commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

I'm not quite sure why you assigned Boxy specifically, this can be reviewed by anybody roughly familiar with parsing. Given the fact that she's pretty busy and already assigned to 3 other PRs of mine, I'm gonna reroll.

@rustbot reroll

@rustbot rustbot assigned khyperia and unassigned BoxyUwU Nov 19, 2026

This branch has not been deployed

No deployments
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

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants