Skip to content

Borrowing from arguments with higher order async functions #66198

Description

@madmaxio

Hi, just wanted to ask if borrow with higher order async fns (from there arguments) is not correct never at all, or there might be some solutions in the future. Please check the example.

use std::future::Future;

async fn f(data: &Vec<String>) {
    
}

async fn start<Fut>(prm: fn(&Vec<String>) -> Fut) 
where
    Fut: Future<Output = ()>
{
    let data = vec![];
    prm(&data).await;
}

fn main() {
    start(f);
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/main.rs:16:11
   |
16 |     start(f);
   |           ^ expected concrete lifetime, found bound lifetime parameter
   |
   = note: expected type `for<'r> fn(&'r std::vec::Vec<std::string::String>) -> _`
              found type `for<'_> fn(&std::vec::Vec<std::string::String>) -> impl std::future::Future {f}`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-lifetimesArea: Lifetimes / regionsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions