Closed
Description
Code
I tried this code:
use core::future::Future;
trait AsyncFn<I, R>: FnMut(I) -> Self::Fut {
type Fut: Future<Output = R>;
}
impl<F, I, R, Fut> AsyncFn<I, R> for F
where
Fut: Future<Output = R>,
F: FnMut(I) -> Fut,
{
type Fut = Fut;
}
async fn call<C, R, Fn>(mut ctx: C, mut f: Fn) -> Result<R, ()>
where
Fn: for<'a> AsyncFn<&'a mut C, Result<R, ()>>,
{
loop {
match f(&mut ctx).await {
Ok(val) => return Ok(val),
Err(_) => continue,
}
}
}
fn test(ctx: &mut usize) {
call(ctx, |ctx| async move {
let _ctx = ctx;
Ok(1usize)
});
}
I expected to see this happen: rustc produces implementation of `FnOnce` is not general enough
Instead, this happened: rustc produces closure/generator type that references itself
Version it worked on
1.65.0
Version with regression
1.67.0-nightly (2022-12-05 e1d8195)
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged