rust/tests/ui/unsized
Stuart Cook 64aea0027a
Rollup merge of #135331 - fmease:ban-assoc-ty-unbounds, r=lcnr
Reject relaxed bounds inside associated type bounds (ATB)

**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 https://github.com/rust-lang/rust/pull/135841#pullrequestreview-2619462717 — some later validation steps only happen during sized elaboration during HIR ty lowering[^1]. Namely, rejecting duplicates (e.g., `?Trait + ?Trait`) and ensuring that `Trait` in `?Trait` is equal to `Sized`[^2]. 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 rust-lang/rust#135841).

This PR rectifies all of this. I cratered this back in 2025-01-10 with (allegedly) no regressions found ([report](https://github.com/rust-lang/rust/pull/135331#issuecomment-2585330783), [its analysis](https://github.com/rust-lang/rust/pull/135331#issuecomment-2585356422)). [However a contributor manually found two occurrences](https://github.com/rust-lang/rust/issues/135229#issuecomment-2581832852) of `TraitRef<AssocTy: ?Sized>` in small hobby projects (presumably via GH code search). I immediately sent downstream PRs: https://github.com/Gui-Yom/turbo-metrics/pull/14, https://github.com/ireina7/summon/pull/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 cost[^3]. 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 rust-lang/rust#135229.

[^1]: I consider this a flaw in the implementation and [I've already added a huge FIXME](82a02aefe0/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs (L195-L207)).
[^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).
2025-08-11 18:22:31 +10:00
..
box-instead-of-dyn-fn.rs Make error message less awkward 2025-02-03 19:00:22 +00:00
box-instead-of-dyn-fn.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
issue-23649-1.rs
issue-23649-2.rs
issue-23649-3.rs
issue-30355.rs
issue-30355.stderr
issue-40231-1.rs
issue-40231-2.rs
issue-71659.current.stderr
issue-71659.next.stderr
issue-71659.rs
issue-75707.rs
issue-75707.stderr
issue-75899-but-gats.rs
issue-75899.rs
issue-91801.rs Make error message less awkward 2025-02-03 19:00:22 +00:00
issue-91801.stderr Make error message less awkward 2025-02-03 19:00:22 +00:00
issue-91803.rs Make error message less awkward 2025-02-03 19:00:22 +00:00
issue-91803.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
issue-97732.rs
issue-115203.rs
issue-115203.stderr
issue-115809.rs Remove polymorphization 2024-12-06 16:42:09 -05:00
issue-115809.stderr
maybe-bounds-where-cpass.rs
param-mentioned-by-different-field.rs
param-mentioned-by-different-field.stderr
relaxed-bounds-invalid-places.rs Reject relaxed bounds inside associated type bounds 2025-07-20 13:30:25 +02:00
relaxed-bounds-invalid-places.stderr Reject relaxed bounds inside associated type bounds 2025-07-20 13:30:25 +02:00
return-unsized-from-trait-method.rs
return-unsized-from-trait-method.stderr
unchanged-param.rs
unsize-coerce-multiple-adt-params.rs
unsized-bare-typaram.rs
unsized-bare-typaram.stderr
unsized-enum.rs
unsized-enum.stderr
unsized-enum2.rs
unsized-enum2.stderr Remove detail from label/note that is already available in other note 2024-10-29 16:26:57 +00:00
unsized-fn-arg.fixed
unsized-fn-arg.rs
unsized-fn-arg.stderr On implicit Sized bound on fn argument, point at type instead of pattern 2024-09-27 00:45:02 +00:00
unsized-fn-param.rs
unsized-fn-param.stderr
unsized-function-argument-41229.rs Rehome tests/ui/issues/ tests [1/?] 2025-07-24 17:01:44 -04:00
unsized-function-argument-41229.stderr Rehome tests/ui/issues/ tests [1/?] 2025-07-24 17:01:44 -04:00
unsized-inherent-impl-self-type.rs
unsized-inherent-impl-self-type.stderr
unsized-struct.rs
unsized-struct.stderr
unsized-trait-impl-self-type.rs
unsized-trait-impl-self-type.stderr Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
unsized-trait-impl-trait-arg.rs
unsized-trait-impl-trait-arg.stderr Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
unsized.rs
unsized2.rs
unsized3-rpass.rs Add missing dyn keywords to tests that do not test for them 2025-06-05 09:41:58 +02:00
unsized3.rs
unsized3.stderr
unsized5.rs
unsized5.stderr
unsized6.rs
unsized6.stderr Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
unsized7.rs
unsized7.stderr Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00