Closed
Description
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