rust/tests
bors 9e394f551c Auto merge of #120752 - compiler-errors:more-relevant-bounds, r=lcnr
Collect relevant item bounds from trait clauses for nested rigid projections

Rust currently considers trait where-clauses that bound the trait's *own* associated types to act like an item bound:

```rust
trait Foo where Self::Assoc: Bar { type Assoc; }
// acts as if:
trait Foo { type Assoc: Bar; }
```

### Background

This behavior has existed since essentially forever (i.e. before Rust 1.0), since we originally started out by literally looking at the where clauses written on the trait when assembling `SelectionCandidate::ProjectionCandidate` for projections. However, looking at the predicates of the associated type themselves was not sound, since it was unclear which predicates were *assumed* and which predicates were *implied*, and therefore this was reworked in #72788 (which added a query for the predicates we consider for `ProjectionCandidate`s), and then finally item bounds and predicates were split in #73905.

### Problem 1: GATs don't uplift bounds correctly

All the while, we've still had logic to uplift associated type bounds from a trait's where clauses. However, with the introduction of GATs, this logic was never really generalized correctly for them, since we were using simple equality to test if the self type of a trait where clause is a projection. This leads to shortcomings, such as:

```rust
trait Foo
where
    for<'a> Self::Gat<'a>: Debug,
{
    type Gat<'a>;
}

fn test<T: Foo>(x: T::Gat<'static>) {
    //~^ ERROR `<T as Foo>::Gat<'a>` doesn't implement `Debug`
    println!("{:?}", x);
}
```

### Problem 2: Nested associated type bounds are not uplifted

We also don't attempt to uplift bounds on nested associated types, something that we couldn't really support until #120584. This can be demonstrated best with an example:

```rust
trait A
    where Self::Assoc: B,
    where <Self::Assoc as B>::Assoc2: C,
{
    type Assoc; // <~ The compiler *should* treat this like it has an item bound `B<Assoc2: C>`.
}

trait B { type Assoc2; }
trait C {}

fn is_c<T: C>() {}

fn test<T: A>() {
    is_c::<<Self::Assoc as B>::Assoc2>();
    //~^ ERROR the trait bound `<<T as A>::Assoc as B>::Assoc2: C` is not satisfied
}
```

Why does this matter?

Well, generalizing this behavior bridges a gap between the associated type bounds (ATB) feature and trait where clauses. Currently, all bounds that can be stably written on associated types can also be expressed as where clauses on traits; however, with the stabilization of ATB, there are now bounds that can't be desugared in the same way. This fixes that.

## How does this PR fix things?

First, when scraping item bounds from the trait's where clauses, given a trait predicate, we'll loop of the self type of the predicate as long as it's a projection. If we find a projection whose trait ref matches, we'll uplift the bound. This allows us to uplift, for example `<Self as Trait>::Assoc: Bound` (pre-existing), but also `<<Self as Trait>::Assoc as Iterator>::Item: Bound` (new).

If that projection is a GAT, we will check if all of the GAT's *own* args are all unique late-bound vars. We then map the late-bound vars to early-bound vars from the GAT -- this allows us to uplift `for<'a, 'b> Self::Assoc<'a, 'b>: Trait` into an item bound, but we will leave `for<'a> Self::Assoc<'a, 'a>: Trait` and `Self::Assoc<'static, 'static>: Trait` alone.

### Okay, but does this *really* matter?

I consider this to be an improvement of the status quo because it makes GATs a bit less magical, and makes rigid projections a bit more expressive.
2024-09-25 21:12:07 +00:00
..
assembly Rollup merge of #130549 - biabbas:riscv32_wrs_vxworks, r=nnethercote 2024-09-25 10:09:22 +02:00
auxiliary
codegen tests: Remove spuriously failing vec-tryinto-array codegen test 2024-09-22 16:46:10 -07:00
codegen-units
coverage Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
coverage-run-rustdoc
crashes Validate unsize coercion in MIR validation 2024-09-25 11:10:38 -04:00
debuginfo Auto merge of #130052 - khuey:clear-dilocation-after-const-emission, r=michaelwoerister 2024-09-13 08:57:41 +00:00
incremental simd_shuffle: require index argument to be a vector 2024-09-14 14:43:24 +02:00
mir-opt be even more precise about "cast" vs "coercion" 2024-09-24 23:12:02 +02:00
pretty Use doc(hidden) instead of allow(missing_docs) in the test harness 2024-09-11 12:14:35 +02:00
run-make Update run-make tests to use cargo wrapper cmd 2024-09-24 19:04:51 +08:00
run-pass-valgrind Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustdoc rustdoc: inherit parent's stability where applicable 2024-09-24 20:18:36 +02:00
rustdoc-gui Rollup merge of #129545 - notriddle:notriddle/toolbar-v2, r=GuillaumeGomez 2024-09-23 23:49:11 -04:00
rustdoc-js rustdoc-search: allow trailing Foo -> arg search 2024-09-05 17:58:05 -07:00
rustdoc-js-std Bless rustdoc-js-std test 2024-09-22 20:35:10 -04:00
rustdoc-json Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustdoc-ui Update rustdoc doctest non_local_defs impl test 2024-09-23 10:01:59 +02:00
ui Auto merge of #120752 - compiler-errors:more-relevant-bounds, r=lcnr 2024-09-25 21:12:07 +00:00
ui-fulldeps Auto merge of #130483 - matthiaskrgr:rollup-q1r0g0y, r=matthiaskrgr 2024-09-17 19:37:03 +00:00
COMPILER_TESTS.md