Skip to content

Syntactically reject equality predicates#153513

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
fmease:gate-eq-pred
Jun 8, 2026
Merged

Syntactically reject equality predicates#153513
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
fmease:gate-eq-pred

Conversation

@fmease

@fmease fmease commented Mar 6, 2026

Copy link
Copy Markdown
Member

View all comments

Background (History)

Equality predicates have been syntactically valid since PR #39158 / nightly-2017-02-02 / 1.16 (released 2017-03-16, 9 years ago), both forms that is: $ty = $ty and $ty == $ty. They're not registered as an unstable feature despite having a tracking issue (#20041). Naturally, they don't have a feature gate. Of course, we reject them post-expansion, so they are still semantically invalid.

Parser scaffolding for $ident = $ty was added in RUST-19391 (2014) which was then generalized to $ty = $ty in RUST-20002 (2014) and extended to additionally cover $ty == $ty in RUST-39158 (2017). As mentioned, the last PR also made them grammatical.

RUST-87471 (2021) attempted to start impl'ing typeck'ing but it was closed due to concerns: #87471 (comment) (already back in 2017 there were concerns: https://github.com/rust-lang/rust/pull/39158/changes#r97811244).

In 2022, T-lang discussed this feature during a meeting and raised concerns: #20041 (comment). However, they were inclined to accept a restricted form, namely T::AssocTy = $ty (T is a (self) ty param or a self ty alias) and <$ty as Trait>::AssocTy = $ty since that's trivial to support in HIR ty lowering (this is still accurate).

Change

This renders equality predicates $ty = $ty and $ty == $ty syntactically invalid again. On stable, they're merely semantically invalid. This is motivated by the fact that

  1. their syntax isn't even decided upon
    1. should it be = or ==?
    2. should the LHS be syntactically restricted to (possibly qualified) paths (i.e., TypePath | QualifiedPathInType), only semantically or not at all?
      • "syntactically" could indeed make sense since we might want to generalize types to so-called terms here (i.e., Type | GenericArgsConst) for mGCA but we can't generalize $ty = $ty to $term = $term due to ambiguities 1 that would require backtracking whereas $typepath = $term wouldn't have that problem
  2. we might (decide to) never impl this feature
    • after all, implementation concerns were raised as early as 9 years ago which are still relevant today even with the next-gen trait solver on the horizon
  3. the compiler + tools contain a bunch of code for dealing with these predicates
    • like lowering, name resolution, rustfmt and Clippy
    • that's entirely useless since they get unconditionally rejected anyway
    • this code doesn't need to exist (for now)

I've merely upgraded the semantic hard error to a syntactic hard error, I've intentionally not introduced an unstable feature under which equality predicates become legal.

That's because a hard error is easier to push through procedurally, it's an important first step (we can always turn it into a feature gate error later on) and since this potential feature isn't backed by any official lang experiment.

I don't consider T-lang's message #20041 (comment) from 2022 to be sufficient because it doesn't answer questions like (1.i), (1.ii) or whether code like T: Trait<A>, <T as Trait<B>>::AssocTy = Ty (AB) or T: Trait<'r>, for<'a> <T as Trait<'a>>::AssocTy = Ty should be legal (which would be more powerful / could lead to typechecking issues, idk) or not assuming we're going with the restricted form ofc (we would need input from T-types).

Lang nomination

#153513 (comment)

Footnotes

  1. Code like fn f() -> i32 where { 0 } is intentionally legal today but if we had $term = $term the { 0 } could then also be the start of an equality predicate like { 0 } = 0.

@fmease fmease added rla-silenced Silences rust-log-analyzer postings to the PR it's added on. C-crater Category: Issue / PR for tracking crater runs labels Mar 6, 2026
@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 Mar 6, 2026
@fmease

fmease commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 6, 2026
[crater only] Syntactically reject equality predicates
@fmease fmease added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 6, 2026
@rust-bors

rust-bors Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 3248bac (3248bace201b6227b0ff78eacc8b00d805551a86, parent: ff086354c9fc93e1da1d2f4d255456624fbcd099)

@fmease

fmease commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-153513 created and queued.
🤖 Automatically detected try build 3248bac
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Mar 6, 2026
@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-153513 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-153513 is completed!
📊 6 regressed and 2 fixed (839795 total)
📊 2542 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-153513/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Mar 15, 2026
@fmease

fmease commented Mar 15, 2026

Copy link
Copy Markdown
Member Author

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-153513-1 created and queued.
🤖 Automatically detected try build 3248bac
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 15, 2026
@fmease fmease changed the title [crater only] Syntactically reject equality predicates Syntactically reject equality predicates Mar 16, 2026
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-lang Relevant to the language team I-lang-nominated Nominated for discussion during a lang team meeting. and removed rla-silenced Silences rust-log-analyzer postings to the PR it's added on. C-crater Category: Issue / PR for tracking crater runs labels Mar 16, 2026
@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-clippy Relevant to the Clippy team. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Apr 12, 2026
@rust-bors

This comment has been minimized.

@jackh726

Copy link
Copy Markdown
Member

r=me with CI fixed

@fmease fmease assigned jackh726 and unassigned JonathanBrouwer Jun 7, 2026
@fmease fmease marked this pull request as ready for review June 7, 2026 16:51
@rustbot

rustbot commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

The Rustfmt subtree was changed

cc @rust-lang/rustfmt

The Clippy subtree was changed

cc @rust-lang/clippy

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 7, 2026
@fmease

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

@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 Jun 7, 2026
@fmease

This comment was marked as outdated.

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 7, 2026
@rust-bors

This comment was marked as outdated.

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 7, 2026
@fmease

fmease commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

@bors r=jackh726

@rust-bors

rust-bors Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ddbf3b9 has been approved by jackh726

It is now in the queue for this repository.

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

Labels

A-rustdoc-json Area: Rustdoc JSON backend disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. rla-silenced Silences rust-log-analyzer postings to the PR it's added on. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting waived-reference-pr This language change does not need a Reference PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: ast validation: index out of bounds: the len is 0 but the index is 18446744073709551615

9 participants