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 causes type checking to spuriously fail #62512

Open
joshlf opened this issue Jul 9, 2019 · 0 comments
Open

Where clause causes type checking to spuriously fail #62512

joshlf opened this issue Jul 9, 2019 · 0 comments
Labels
A-typesystem Area: The 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-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@joshlf
Copy link
Contributor

joshlf commented Jul 9, 2019

I have the following code on Rust 1.36.0 Stable (playground):

trait Foo<Input> {
    type Output;
}

trait Bar {
    type Input;

    fn baz<F: Foo<Self::Input>>() -> F::Output
    where
        F::Output: Default;
}

impl<T> Bar for T {
    type Input = T;

    fn baz<F: Foo<Self::Input>>() -> F::Output
    where
        F::Output: Default,
    {
    }
}

I would expect this to compile, but Rust seems confused by the fact that, in the <T as Bar>::baz implementation, the F type parameter is both Foo<Self::Input> and Foo<T> (T and Self::Input are the same type) and complains that it expects F to also implement Foo<T>:

error[E0277]: the trait bound `F: Foo<T>` is not satisfied
  --> src/lib.rs:16:5
   |
16 | /     fn baz<F: Foo<Self::Input>>() -> F::Output
17 | |     where
18 | |         F::Output: Default,
19 | |     {
20 | |     }
   | |_____^ the trait `Foo<T>` is not implemented for `F`
   |
   = help: consider adding a `where F: Foo<T>` bound

However, following the advice of adding a Foo<T> bound, Rust is again confused by thinking that Foo<Self::Input> and Foo<T> are two different traits:

error[E0221]: ambiguous associated type `Output` in bounds of `F`
  --> src/lib.rs:18:9
   |
2  |     type Output;
   |     ------------
   |     |
   |     ambiguous `Output` from `Foo<T>`
   |     ambiguous `Output` from `Foo<<T as Bar>::Input>`
...
18 |         F::Output: Default,
   |         ^^^^^^^^^ ambiguous associated type `Output`

error[E0221]: ambiguous associated type `Output` in bounds of `F`
  --> src/lib.rs:16:38
   |
2  |     type Output;
   |     ------------
   |     |
   |     ambiguous `Output` from `Foo<T>`
   |     ambiguous `Output` from `Foo<<T as Bar>::Input>`
...
16 |     fn baz<F: Foo<Self::Input>>() -> F::Output
   |                                      ^^^^^^^^^ ambiguous associated type `Output`
@jonas-schievink jonas-schievink added A-typesystem Area: The 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-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The 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-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants