Cycle detected in async fn but not with -> impl Future #119727
Closed as not planned
Description
opened on Jan 8, 2024
Here is the reproducer:
use std::future::Future;
use futures::FutureExt;
struct Object(Box<Object>);
trait Trait {
fn iter(&self) -> impl Sized + Send + Future<Output = ()>;
}
impl Trait for Object {
// Compiles
#[cfg(any())]
fn iter(&self) -> impl Sized + Send + Future<Output = ()> {
async move {
self.0.iter().boxed().await;
}
}
// Does not compile
#[cfg(all())]
async fn iter(&self) {
self.0.iter().boxed().await;
}
}
Interestingly, if you swap the any/all, then the version with -> impl Sized + Send + Future<Output = ()>
does compile properly.
So something in async fn
is not just desugared as -> impl Sized + Send + Future
, but I'm not sure why that is?
Possibly related to:
Activity