os-rust/tests/ui/impl-trait/in-trait
bors 21d94a3d2c Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obk
Stabilize associated type bounds (RFC 2289)

This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses.

### What are we stabilizing?

We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation.

In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info).

Associated type bounds are stabilized in four positions:
* **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`.
* **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629.
* **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`.
* **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound.

The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds.

### How does this differ from the RFC?

Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular:
* It does *not* desugar to anonymous associated items in associated type item bounds.
* It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds.

This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example:
* Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531.
* Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types.

This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719.

### Implementation history:

Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out--
* #57428
* #108063
* #110512
* #112629
* #120719
* #120584

Closes #52662

[RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-19 00:04:09 +00:00
..
auxiliary Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
alias-bounds-when-not-wf.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
alias-bounds-when-not-wf.stderr Gracefully handle non-WF alias in assemble_alias_bound_candidates_recur 2024-02-10 23:49:21 +00:00
anonymize-binders-for-refine.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
assumed-wf-bounds-in-impl.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
async-and-ret-ref.rs Print RPITIT like an opaque 2024-02-27 17:43:40 +00:00
async-and-ret-ref.stderr Print RPITIT like an opaque 2024-02-27 17:43:40 +00:00
bad-item-bound-within-rpitit-2.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
bad-item-bound-within-rpitit-2.stderr Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
bad-item-bound-within-rpitit.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
bad-item-bound-within-rpitit.stderr Split refining_impl_trait lint into _reachable, _internal variants 2024-03-05 16:19:16 -08:00
box-coerce-span-in-default.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
check-wf-on-non-defaulted-rpitit.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
check-wf-on-non-defaulted-rpitit.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
cycle-effective-visibilities-during-object-safety.rs Deduplicate more sized errors on call exprs 2024-01-24 02:53:15 +00:00
cycle-effective-visibilities-during-object-safety.stderr Deduplicate more sized errors on call exprs 2024-01-24 02:53:15 +00:00
deep-match-works.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
deep-match.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
deep-match.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
default-body-type-err-2.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
default-body-type-err-2.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
default-body-type-err.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
default-body-type-err.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
default-body-with-rpit.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
default-body.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
default-method-binder-shifting.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
default-method-constraint.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
doesnt-satisfy.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
doesnt-satisfy.stderr rename RPITIT from opaque to synthetic 2024-02-27 17:43:40 +00:00
dont-project-to-rpitit-with-no-value.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
dont-project-to-rpitit-with-no-value.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
early.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
encode.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
ensure-rpitits-are-created-before-freezing.rs Ensure RPITITs are created before def-id freezing 2024-03-14 20:30:57 -04:00
ensure-rpitits-are-created-before-freezing.stderr Ensure RPITITs are created before def-id freezing 2024-03-14 20:30:57 -04:00
foreign-dyn-error.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
foreign-dyn-error.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
foreign.rs Split refining_impl_trait lint into _reachable, _internal variants 2024-03-05 16:19:16 -08:00
foreign.stderr Split refining_impl_trait lint into _reachable, _internal variants 2024-03-05 16:19:16 -08:00
gat-outlives.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
gat-outlives.stderr Fix outlives suggestion for GAT in RPITIT 2023-10-16 15:42:26 +00:00
generics-mismatch.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
generics-mismatch.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-102140.rs Deduplicate more sized errors on call exprs 2024-01-24 02:53:15 +00:00
issue-102140.stderr Deduplicate more sized errors on call exprs 2024-01-24 02:53:15 +00:00
issue-102301.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
issue-102571.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
issue-102571.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
lifetime-in-associated-trait-bound.rs Stabilize associated type bounds 2024-03-08 20:56:25 +00:00
method-signature-matches.lt.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
method-signature-matches.mismatch.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
method-signature-matches.mismatch_async.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
method-signature-matches.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
method-signature-matches.too_few.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
method-signature-matches.too_many.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
missing-lt-outlives-in-rpitit-114274.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
missing-lt-outlives-in-rpitit-114274.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
missing-static-bound-from-impl.rs Print RPITIT like an opaque 2024-02-27 17:43:40 +00:00
missing-static-bound-from-impl.stderr Print RPITIT like an opaque 2024-02-27 17:43:40 +00:00
nested-rpitit-bounds.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
nested-rpitit.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
object-safety-sized.rs Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
object-safety.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
object-safety.stderr On object safety error, mention new enum as alternative 2023-10-29 23:55:46 +00:00
opaque-and-lifetime-mismatch.rs Don't ICE if we collect no RPITITs unless there are no unification errors 2024-03-08 15:52:29 +00:00
opaque-and-lifetime-mismatch.stderr Don't ICE if we collect no RPITITs unless there are no unification errors 2024-03-08 15:52:29 +00:00
opaque-in-impl-is-opaque.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
opaque-in-impl-is-opaque.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
opaque-in-impl.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
opaque-variances.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
outlives-in-nested-rpit.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
placeholder-implied-bounds.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
refine-normalize.rs Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
refine.rs Split refining_impl_trait lint into _reachable, _internal variants 2024-03-05 16:19:16 -08:00
refine.stderr Split refining_impl_trait lint into _reachable, _internal variants 2024-03-05 16:19:16 -08:00
return-dont-satisfy-bounds.rs Consolidate WF for aliases 2024-03-14 12:17:00 -04:00
return-dont-satisfy-bounds.stderr Consolidate WF for aliases 2024-03-14 12:17:00 -04:00
reveal.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
rpitit-cycle-in-generics-of.rs Uplift some feeding out of associated_type_for_impl_trait_in_impl and into queries 2024-03-05 15:55:31 +00:00
rpitit-hidden-types-self-implied-wf-via-param.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
rpitit-hidden-types-self-implied-wf-via-param.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
rpitit-hidden-types-self-implied-wf.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
rpitit-hidden-types-self-implied-wf.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
rpitit-shadowed-by-missing-adt.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
rpitit-shadowed-by-missing-adt.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
sibling-function-constraint.rs Test that RPITITs have RPIT scope and not impl-wide scope 2023-10-13 21:01:36 +00:00
sibling-function-constraint.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
signature-mismatch.failure.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
signature-mismatch.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
span-bug-issue-121457.rs Revert some span_bugs to span_delayed_bug. 2024-02-23 10:04:32 +11:00
span-bug-issue-121457.stderr Revert some span_bugs to span_delayed_bug. 2024-02-23 10:04:32 +11:00
specialization-broken.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
specialization-broken.stderr recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05:00
specialization-substs-remap.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
success.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
suggest-missing-item.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
suggest-missing-item.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
suggest-missing-item.stderr Update tests 2024-02-07 10:42:01 +08:00
trait-more-generics-than-impl.rs Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
trait-more-generics-than-impl.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
unconstrained-lt.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
unconstrained-lt.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
variance.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
variance.stderr Test variances of opaque captures 2023-08-28 01:05:34 +00:00
variances-of-gat.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
wf-bounds.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
wf-bounds.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
where-clause.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00