Skip to content
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

Use bound vars for GAT params in param_env in check_type_bounds #87900

Merged
merged 3 commits into from
Aug 24, 2021

Conversation

jackh726
Copy link
Member

@jackh726 jackh726 commented Aug 9, 2021

Fixes #87429

@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 9, 2021
// the *trait* with the generic associated type parameters.
let impl_ty_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
// - `impl_trait_ref` would be `<(A, B) as Foo<u32>>
// - `impl_ty_substs` would be `[A, B, ^0.0]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use C instead of ^0.0 here? This might be unnecessarily confusing to someone reading that comment?

@nagisa
Copy link
Member

nagisa commented Aug 14, 2021

I'm not a great reviewer for this. Is there anybody else who could review this?

@nagisa
Copy link
Member

nagisa commented Aug 14, 2021

r? rust-lang/compiler-team

@rust-highfive rust-highfive assigned oli-obk and unassigned nagisa Aug 14, 2021
@jackh726
Copy link
Member Author

r? @nikomatsakis

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 23, 2021

📌 Commit b017077 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2021
@bors
Copy link
Contributor

bors commented Aug 24, 2021

⌛ Testing commit b017077 with merge b5fe3bc...

@bors
Copy link
Contributor

bors commented Aug 24, 2021

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing b5fe3bc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 24, 2021
@bors bors merged commit b5fe3bc into rust-lang:master Aug 24, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 24, 2021
@jackh726 jackh726 deleted the issue-87429 branch August 24, 2021 18:14
@jackh726 jackh726 restored the issue-87429 branch March 12, 2022 18:30
@jackh726 jackh726 deleted the issue-87429 branch March 12, 2022 18:35
@jackh726 jackh726 restored the issue-87429 branch March 12, 2022 18:42
@jackh726 jackh726 deleted the issue-87429 branch March 12, 2022 18:52
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Mar 28, 2023
…d, 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 rust-lang#87900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatched types issue with GATs
9 participants