Skip to content

Strange borrowing issue in inherent async method. #68950

Closed
@crlf0710

Description

@crlf0710

Not sure whether it's a bug, but it is indeed strange...

struct A;
// this compiles
fn test(s: &mut A, arg: &str, handler: Box<dyn Fn() + 'static>) {
        
}
// this doesn't
impl A {
    async fn test2(&mut self, arg: &str, handler: Box<dyn Fn() + 'static>) {
        
    }
}

test2 errors with:

error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
  --> src/lib.rs:8:76
   |
8  |     async fn test2(&mut self, arg: &str, handler: Box<dyn Fn() + 'static>) {
   |                                                                            ^
   |

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions