Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no recursion" check will not work for async fns/generators in traits #2927

Open
Diggsey opened this issue May 16, 2020 · 2 comments
Open

"no recursion" check will not work for async fns/generators in traits #2927

Diggsey opened this issue May 16, 2020 · 2 comments

Comments

@Diggsey
Copy link
Contributor

Diggsey commented May 16, 2020

We currently check that async fns and generators are not recursive, as this would generate infinitely large state machines. However, if we ever want to support async fns or generators in traits, this check would have to run post-monomorphisation (since until that point we don't know which trait implementation will be chosen).

Since we don't like to generate errors post-monomorphisation, this seems like a serious problem!

Example:

trait Foo {
    async fn foo(&self);
}

impl Foo for i32 {
    async fn foo(&self, other: &impl Foo) {
        other.foo().await;
    }
}

impl Foo for i64 {
    async fn foo(&self, other: &impl Foo) {
        // Not recursive
    }
}

fn main() {
    let x = 1i32;
    x.foo(&x); // Error
}
@RustyYato
Copy link

Currently it is possible to generate error after monomorphozation using erroneous constants in traits.

@comex
Copy link

comex commented May 16, 2020

See also: rust-lang/rust#32498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants