-
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
…er-errors More robustly deal with relaxed bounds and improve their diagnostics Scaffolding for rust-lang#135229 (CC rust-lang#135331) Fixes rust-lang#136944 (6th commit). Fixes rust-lang#142718 (8th commit).
…er-errors More robustly deal with relaxed bounds and improve their diagnostics Scaffolding for rust-lang#135229 (CC rust-lang#135331) Fixes rust-lang#136944 (6th commit). Fixes rust-lang#142718 (8th commit).
e7050cb
to
ad13619
Compare
Can we open PRs against the affected crates? I imagine it'd be trivial to do so and there arent that many crates either |
I already did so back in January as mentioned in the PR description:
|
More robustly deal with relaxed bounds and improve their diagnostics Scaffolding for rust-lang/rust#135229 (CC rust-lang/rust#135331) Fixes rust-lang/rust#136944 (6th commit). Fixes rust-lang/rust#142718 (8th commit).
ad13619
to
788fb08
Compare
…er-errors More robustly deal with relaxed bounds and improve their diagnostics Scaffolding for rust-lang#135229 (CC rust-lang#135331) Fixes rust-lang#136944 (6th commit). Fixes rust-lang#142718 (8th commit).
This seems fine to me, but imo is more of @rust-lang/lang than types, given that it's just a user-visible change of "do we allow |
Hmm, I see your point here. We landed #135841 as a pure T-types FCP with a T-lang ping in #135841 (comment) 🤔 To me it feels slightly less clear cut than e.g. a decision about the syntax of such opt-out bounds 🤔 Deciding how / whether to handle where-bounds which are meaningless/incorrect is certainly at the intersection of Types and Lang, though I don't think I would have complained if we originally started this as a pure Lang FCP. If T-lang minds I am open to give this decision over to them. |
We're fully caught up on nominations, so we should get to it this Wednesday. If you cancel the FCP, I'll restart immediately, as it does seem clearly desirable, and I'd expect it to sail through. |
@rfcbot fcp cancel |
@lcnr proposal cancelled. |
@rust-lang/lang: This is about rejecting code like this: fn f<T>() where T: Trait<Ty: ?Sized> {}
trait Trait { type Ty; } We already reject this: fn f<T>() where T: Trait, T::Ty: ?Sized {} //~ ERROR
trait Trait { type Ty; } The crater run is apparently clean. @rfcbot fcp merge |
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. |
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). ↩