-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
base: master
Are you sure you want to change the base?
Conversation
@bors try |
[crater-only] Ban assoc ty unbounds cc rust-lang#135229 r? ghost
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Based on running Crater Analysis on this crater report full automated report
|
TraitRef<AssocTy: …>
)
TraitRef<AssocTy: …>
)TraitRef<AssocTy: …>
)
TraitRef<AssocTy: …>
)5c245de
to
e7050cb
Compare
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. |
except for 2 hobby projects only on GitHub for which @fmease opened fixes back in January which have since been ignored. |
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 |
@bors try |
Reject relaxed bounds inside associated type bounds (ATB)
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
@rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
🎉 Experiment
|
Update: Crater found two new root regressions. One ( I've already sent out new "incoming breakage" PRs: pacman-repo-builder/arch-pkg-text#25 and PaulmannLighting/le-stream#1. |
Reject relaxed bounds — most notably
?Sized
— inside associated type boundsTraitRef<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 toTraitRef<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 thatTrait
in?Trait
is equal toSized
2. As you can probably guess, on stable/master we don't run these checks for ATBs (so we allow even more nonsensical bounds likeIterator<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
I consider this a flaw in the implementation and I've already added a huge FIXME. ↩
To be more precise, if the internal flag
-Zexperimental-default-bounds
is provided other "default traits" (needs internal featurelang_items
) are permitted as well (cc closely related internal feature:more_maybe_bounds
). ↩Having to track this and adding an entire lint whose remnants would remain in the code base forever (we never fully remove lints). ↩