Open
Description
opened on Oct 24, 2023
This is boiled down reproducible example.
I tried this code:
use std::future::Future;
pub struct Test<T, U, R, F>
where
U: Future<Output = Option<R>>,
F: Fn(&mut T) -> U,
{
ty: T,
fun: F
}
impl<T, U, R, F> Test<T, U, R, F>
where
U: Future<Output = Option<R>>,
F: Fn(&mut T) -> U,
{
fn new(ty: T, fun: F) -> Self {
Self { ty, fun }
}
}
struct Ty {
v: Vec<u32>,
}
impl Ty {
async fn recv(&mut self) -> Option<u32> {
self.v.pop()
}
}
pub async fn run() {
let ty = Ty { v: vec![] };
let mut test = Test::new(ty, Ty::recv);
while let Some(_v) = (test.fun)(&mut test.ty).await {}
}
Compiler throws errors:
error[E0308]: mismatched types
--> crates\render\src\regui.rs:68:20
|
68 | let mut test = Test::new(ty, Ty::recv);
| ^^^^^^^^^ one type is more general than the other
|
= note: expected opaque type `impl for<'a> Future<Output = Option<u32>>`
found opaque type `impl Future<Output = Option<u32>>`
= help: consider `await`ing on both `Future`s
= note: distinct uses of `impl Trait` result in different opaque types
error: higher-ranked lifetime error
--> crates\render\src\regui.rs:68:20
|
68 | let mut test = Test::new(ty, Ty::recv);
| ^^^^^^^^^^^^^^^^^^^^^^^
error: higher-ranked lifetime error
--> crates\render\src\regui.rs:68:20
|
68 | let mut test = Test::new(ty, Ty::recv);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: could not prove `Test<Ty, impl Future<Output = Option<u32>>, u32, for<'a> fn(&'a mut Ty) -> impl Future<Output = Option<u32>> {Ty::recv}> well-formed`
Activity