"no recursion" check will not work for async fns/generators in traits
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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