Skip to content

Cycle detected in async fn but not with -> impl Future #119727

Closed as not planned
Closed as not planned
@Ekleog

Description

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;
    }
}

(playground link)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.F-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]`I-cycleIssue: A query cycle occurred while none was expectedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & await

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions