rust/compiler/rustc_hir_analysis/src/check
nils 7e90732abe
Rollup merge of #109470 - compiler-errors:gat-normalize-bound, r=jackh726
Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`

Given:

```rust
trait Foo {
    type Assoc<T>: PartialEq<Self::Assoc<i32>>;
}

impl Foo for () {
    type Assoc<T> = Wrapper<T>;
}

struct Wrapper<T>(T);

impl<T> PartialEq<Wrapper<i32>> for Wrapper<T> { }
```

We add an additional predicate in the `normalize_param_env` in `check_type_bounds` that is used to normalize the GAT's bounds to check them in the impl. Problematically, though, that predicate is constructed to be `for<^0> <() as Foo>::Assoc<^0> => Wrapper<T>`, instead of `for<^0> <() as Foo>::Assoc<^0> => Wrapper<^0>`.

That means `Self::Assoc<i32>` in the bounds that we're checking normalizes to `Wrapper<T>`, instead of `Wrapper<i32>`, and so the bound `Self::Assoc<T>: PartialEq<Self::Assoc<i32>>` normalizes to `Wrapper<T>: PartialEq<Wrapper<T>>`, which does not hold.

Fixes this by properly substituting the RHS of that normalizes predicate that we add to the `normalize_param_env`. That means the bound is properly normalized to `Wrapper<T>: PartialEq<Wrapper<i32>>`, which *does* hold.

---

The second commit in this PR just cleans up some substs stuff and some naming.

r? `@jackh726` cc #87900
2023-03-28 12:51:13 +02:00
..
check.rs RPITITs are DefKind::Opaque with new lowering strategy 2023-03-21 23:36:07 +00:00
compare_impl_item.rs Clean up substs building 2023-03-22 18:16:01 +00:00
dropck.rs diagnostics: if AssocFn has self argument, describe as method 2023-02-22 08:40:33 -07:00
intrinsic.rs Rollup merge of #109179 - llogiq:intrinsically-option-as-slice, r=eholk 2023-03-23 00:00:31 +05:30
intrinsicck.rs Use FxIndexSet instead of FxHashSet for asm_target_features query. 2023-03-01 10:19:26 +01:00
mod.rs Rollup merge of #109414 - spastorino:new-rpitit-16, r=compiler-errors 2023-03-23 00:00:35 +05:30
region.rs Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstrieb 2023-01-20 04:52:28 +00:00
wfcheck.rs Don't elaborate non-obligations into obligations 2023-03-26 20:33:54 +00:00