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

where clause shadows information about higher impls #38071

Open
Twey opened this issue Nov 29, 2016 · 2 comments
Open

where clause shadows information about higher impls #38071

Twey opened this issue Nov 29, 2016 · 2 comments
Labels
A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@Twey
Copy link

Twey commented Nov 29, 2016

It appears that the typechecker, on encountering a where clause, will assume the impl information given in the where bound and stop looking for impls, thus missing additional information that may be available about the impl outside the item.

For example, this code doesn't typecheck:

pub trait Id { type Id; }
impl<T> Id for T { type Id = T; }

pub fn foo<A>(a: A) -> <A as Id>::Id
where A: Id
{ a }

giving the error:

hkt-mwe.rs:6:3: 6:4 error: mismatched types [E0308]
hkt-mwe.rs:6 { a }
               ^
hkt-mwe.rs:6:3: 6:4 help: run `rustc --explain E0308` to see a detailed explanation
hkt-mwe.rs:6:3: 6:4 note: expected type `<A as Id>::Id`
hkt-mwe.rs:6:3: 6:4 note:    found type `A`

but the same code without the where-bound, which should be entirely redundant since it provides only information already known to the type-checker, compiles.

This makes putting emulated HKTs into traits difficult, as a type that depends on such a thing must have a where clause in the trait that, though redundant, must appear in the impl to avoid E0195.

Edit: Current error:

error[[E0308]](https://doc.rust-lang.org/stable/error_codes/E0308.html): mismatched types
 --> src/lib.rs:6:3
  |
4 | pub fn foo<A>(a: A) -> <A as Id>::Id
  |            -           ------------- expected `<A as Id>::Id` because of return type
  |            |
  |            this type parameter
5 | where A: Id
6 | { a }
  |   ^ expected associated type, found type parameter `A`
  |
  = note: expected associated type `<A as Id>::Id`
              found type parameter `A`
help: consider further restricting this bound
  |
5 | where A: Id + Id<Id = A>
  |             ++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error
@steveklabnik steveklabnik added A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 29, 2016
@hanna-kruppe
Copy link
Contributor

At a glance it looks related to #24066 but it may also be simply missing normalization.

@Mark-Simulacrum
Copy link
Member

Can someone confirm that this is #24066? I think it is, since it's masking other impls, but I'm uncertain.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants