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

Associated type equality fails with trait bound on struct #51446

Closed
stephaneyfx opened this issue Jun 8, 2018 · 1 comment · Fixed by #83806
Closed

Associated type equality fails with trait bound on struct #51446

stephaneyfx opened this issue Jun 8, 2018 · 1 comment · Fixed by #83806
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@stephaneyfx
Copy link
Contributor

This may be related/identical to #47897 and #37883.

The following code fails to compile with a dubious error. This is a simplified reproduction example based on @DutchGhost's code on IRC. Note that commenting the where clause in the definition of struct B makes the code compile. playground

trait Foo {
    type Item;
    fn get(&self) -> Self::Item;
}

fn blah<T, F>(x: T, f: F) -> B<T::Item, impl Fn(T::Item)>
where
    T: Foo,
    F: Fn(T::Item),
{
    B {x: x.get(), f}
}

struct B<T, F>
// Comment the 2 following lines to make the compiler happy
where
    F: Fn(T),
{
    x: T,
    f: F,
}

impl Foo for i32 {
    type Item = i32;
    fn get(&self) -> i32 {*self}
}

fn main() {
    let _ = blah(0, |_| ());
}
error[E0277]: the trait bound `impl std::ops::Fn<(<i32 as Foo>::Item,)>: std::ops::Fn<(i32,)>` is not satisfied
  --> src/main.rs:29:13
   |
29 |     let _ = blah(0, |_| ());
   |             ^^^^^^^^^^^^^^^ the trait `std::ops::Fn<(i32,)>` is not implemented for `impl std::ops::Fn<(<i32 as Foo>::Item,)>`
   |
note: required by `B`
  --> src/main.rs:14:1
   |
14 | / struct B<T, F>
15 | | // Comment the 2 following lines to make the compiler happy
16 | | where
17 | |     F: Fn(T),
...  |
20 | |     f: F,
21 | | }
   | |_^

error: aborting due to previous error
@stokhos stokhos assigned stokhos and unassigned stokhos Jun 9, 2018
@stokhos stokhos added A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jun 9, 2018
@estebank estebank added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 2, 2021
@estebank
Copy link
Contributor

estebank commented Feb 2, 2021

This code now compiles. It just needs a test to close.

@bors bors closed this as completed in 28b948f Apr 11, 2021
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants