rust-lang / rust-lang/rfcs

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

Open
#2,927 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's async-trait example and review how the existing no-recursion check is performed for async functions and generators. Trace where trait implementation selection and monomorphisation occur, then determine a design that detects recursive state-machine generation without introducing post-monomorphisation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.