Skip to content

Reject relaxed bounds inside associated type bounds (ATB) #135331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fmease
Copy link
Member

@fmease fmease commented Jan 10, 2025

Reject relaxed bounds — most notably ?Sized — inside associated type bounds TraitRef<AssocTy: …>.

This was previously accepted without warning despite being incorrect: ATBs are not a place where we perform sized elaboration, meaning TraitRef<AssocTy: …> does not elaborate to TraitRef<AssocTy: Sized + …> if doesn't contain ?Sized. Therefore ?Sized is meaningless. In no other (stable) place do we (intentionally) allow relaxed bounds where we don't also perform sized elab, this is highly inconsistent and confusing! Another point of comparison: For the desugared $SelfTy: TraitRef, $SelfTy::AssocTy: … we don't do sized elab either (and thus also don't allow relaxed bounds).

Moreover — as I've alluded to back in #135841 (review) — some later validation steps only happen during sized elaboration during HIR ty lowering1. Namely, rejecting duplicates (e.g., ?Trait + ?Trait) and ensuring that Trait in ?Trait is equal to Sized2. As you can probably guess, on stable/master we don't run these checks for ATBs (so we allow even more nonsensical bounds like Iterator<Item: ?Copy> despite T-types's ruling established in the FCP'ed #135841).

This PR rectifies all of this. I cratered this back in 2025-01-10 with (allegedly) no regressions found (report, its analysis). However a contributor manually found two occurrences of TraitRef<AssocTy: ?Sized> in small hobby projects (presumably via GH code search). I immediately sent downstream PRs: Gui-Yom/turbo-metrics#14, ireina7/summon#1 (however, the owners have showed no reaction so far).

I'm leaning towards banning these forms without a FCW because a FCW isn't worth the maintenance cost3. Note that associated type bounds were stabilized in 1.79.0 (released 2024-06-13 which is 13 months ago), so the proliferation of ATBs shouldn't be that high yet. If you think we should do another crater run since the last one was 6 months ago, I'm fine with that.

Fixes #135229.

Footnotes

  1. I consider this a flaw in the implementation and I've already added a huge FIXME.

  2. To be more precise, if the internal flag -Zexperimental-default-bounds is provided other "default traits" (needs internal feature lang_items) are permitted as well (cc closely related internal feature: more_maybe_bounds).

  3. Having to track this and adding an entire lint whose remnants would remain in the code base forever (we never fully remove lints).

@fmease fmease added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Jan 10, 2025
@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 Jan 10, 2025
@fmease
Copy link
Member Author

fmease commented Jan 10, 2025

@bors try

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2025
@bors
Copy link
Collaborator

bors commented Jan 10, 2025

⌛ Trying commit 5c245de with merge de39175...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 10, 2025
@bors
Copy link
Collaborator

bors commented Jan 10, 2025

☀️ Try build successful - checks-actions
Build commit: de39175 (de39175d9e0f63ff8967b81f9639ba28d11ae6ef)

@fmease
Copy link
Member Author

fmease commented Jan 10, 2025

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-135331 created and queued.
🤖 Automatically detected try build de39175
🔍 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 Jan 10, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-135331 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-135331 is completed!
📊 117 regressed and 36 fixed (566362 total)
📰 Open the full 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

@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 Jan 11, 2025
@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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2025
@Skgland
Copy link
Contributor

Skgland commented Jan 11, 2025

Based on running Crater Analysis on this crater report
110 out of 117 build failed (unknown) regressions appear spurious caused by running out of disk space, i.e. their logs contain the string no space left on device.
The remaining seven appear to be spurious as well, based on manual review of the logs.

full automated report
Regressed: 117
build failed(unknown): 117
----------------------------------
Results:
no-space: 110
----------------------------------
sum: 110
others: 7
----------------------------------
[
    (
        "ceronman.writing-a-c-compiler.ce987db61026febea0e12806e99932b735808d61",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/gh/ceronman.writing-a-c-compiler",
    ),
    (
        "benrussell.simple_open-rs.feb28e8321d6c3db2cd5b20a6c009c70db767118",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/gh/benrussell.simple_open-rs",
    ),
    (
        "dennisoelkers.brghtnss.43a8295abe3b93dfc257f7908710ef7bb4d2675e",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/gh/dennisoelkers.brghtnss",
    ),
    (
        "gauteh.hidefix.5569aa88689b7dd1867354103e0485894b0d06ec",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/gh/gauteh.hidefix",
    ),
    (
        "smasher164.judgefmt.945d1d88d4083018bcd997df019a03656bc24865",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/gh/smasher164.judgefmt",
    ),
    (
        "pillow-routing-0.4.2",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/reg/pillow-routing-0.4.2",
    ),
    (
        "tree-sitter-po-0.0.1",
        "try%23de39175d9e0f63ff8967b81f9639ba28d11ae6ef/reg/tree-sitter-po-0.0.1",
    ),
]

rust-bors bot added a commit that referenced this pull request Jun 20, 2025
More robustly deal with relaxed bounds and improve their diagnostics

Scaffolding for #135229 (CC #135331)

Fixes #136944.
Fixes #142718.
rust-bors bot added a commit that referenced this pull request Jun 28, 2025
More robustly deal with relaxed bounds and improve their diagnostics

Scaffolding for #135229 (CC #135331)

Fixes #136944.
Fixes #142718.
@fmease fmease added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Jul 18, 2025
@fmease fmease changed the title [crater-only] Ban assoc ty unbounds Reject relaxed bounds inside associated type bounds (ATB, TraitRef<AssocTy: …>) Jul 18, 2025
@fmease fmease changed the title Reject relaxed bounds inside associated type bounds (ATB, TraitRef<AssocTy: …>) [STACKED] Reject relaxed bounds inside associated type bounds (ATB, TraitRef<AssocTy: …>) Jul 18, 2025
@fmease fmease changed the title [STACKED] Reject relaxed bounds inside associated type bounds (ATB, TraitRef<AssocTy: …>) [STACKED] Reject relaxed bounds inside associated type bounds (ATB) Jul 18, 2025
@fmease fmease force-pushed the ban-assoc-ty-unbounds branch from 5c245de to e7050cb Compare July 18, 2025 10:58
@fmease fmease removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Jul 18, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jul 28, 2025

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jul 28, 2025
@traviscross traviscross added the I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination label Jul 28, 2025
@lcnr
Copy link
Contributor

lcnr commented Jul 28, 2025

The crater run is apparently clean.

except for 2 hobby projects only on GitHub for which @fmease opened fixes back in January which have since been ignored.

@tmandry
Copy link
Member

tmandry commented Jul 30, 2025

I'd feel more comfortable if we had a more recent crater run than 6 months. I think it is unlikely that that would surface anything to block this PR, maybe prompt some more PRs to existing projects. I would especially want to know if it hits anything on crates.io with deps. We can do that asynchronously with getting this landed, so

@rfcbot reviewed

@fmease
Copy link
Member Author

fmease commented Jul 30, 2025

@bors try

@rust-bors
Copy link

rust-bors bot commented Jul 30, 2025

⌛ Trying commit 788fb08 with merge 29194e8

To cancel the try build, run the command @bors try cancel.

rust-bors bot added a commit that referenced this pull request Jul 30, 2025
Reject relaxed bounds inside associated type bounds (ATB)
@rust-bors
Copy link

rust-bors bot commented Jul 30, 2025

☀️ Try build successful (CI)
Build commit: 29194e8 (29194e8f603400afdb2f86c9418e9fccb1628ea0, parent: ba7e63b63871a429533c189adbfb1d9a6337e000)

@fmease
Copy link
Member Author

fmease commented Jul 30, 2025

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-135331-1 created and queued.
🤖 Automatically detected try build 29194e8
🔍 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 Jul 30, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-135331-1 is now running

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

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jul 30, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jul 30, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Jul 31, 2025
@craterbot
Copy link
Collaborator

🎉 Experiment pr-135331-1 is completed!
📊 14 regressed and 9 fixed (673600 total)
📰 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

@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 Jul 31, 2025
@fmease
Copy link
Member Author

fmease commented Jul 31, 2025

Update: Crater found two new root regressions.

One (le-stream-3.6.3) doesn't have any dependents and the other one (KSXGitHub.parse-arch-pkg-desc) has a dependent by the same org / author (KSXGitHub.arch-pkg-db). All other ones are spurious.

I've already sent out new "incoming breakage" PRs: pacman-repo-builder/arch-pkg-text#25 and PaulmannLighting/le-stream#1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. 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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Relaxed bounds in associated type bounds don't get rejected