Skip to content

error where expected and found future are the same #112010

Closed as not planned
Closed as not planned
@rbtcollins

Description

@rbtcollins

I tried this code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5c0da276115b23a4478fd825fb91f21a

(I'm trying to get some way to port the rustup test suite which uses closures to run test within the context of the framework over to async code)

I got this error:

23 |     call_a_callback(make_future);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected trait `for<'a> <for<'a> fn(&'a str) -> impl Future<Output = ()> + 'a {make_future} as FnOnce<(&'a str,)>>`
              found trait `for<'a> <for<'a> fn(&'a str) -> impl Future<Output = ()> + 'a {make_future} as FnOnce<(&'a str,)>>`
note: the lifetime requirement is introduced here
  --> src/main.rs:5:20
   |
5  |     F: Fn(&str) -> FR,
   |                    ^^

On

Nightly version: 1.71.0-nightly
(2023-05-25 a2b1646c597329d0a25e

The following error

16 | fn make_future<'a>(s: &'a str) -> impl Future<Output=()>+ 'a {
   |                                   --------------------------
   |                                   |
   |                                   the expected future
   |                                   the found future
...
23 |     call_a_callback(make_future);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected opaque type `impl for<'a> Future<Output = ()> + '_`
              found opaque type `impl Future<Output = ()> + '_`
   = help: consider `await`ing on both `Future`s
   = note: distinct uses of `impl Trait` result in different opaque types

Meta

rustc --version --verbose: (from playground, not sure how to get --verbose there)

1.69.0
<version>

I'm not entirely sure what is going on.

What I hoped would happen is that the future returned from make_future would be suitable for awaiting on in call_a_callback - the bigger picture is I'm trying to port rustups test suite to async, and this is a minimal reproduction of the code style there, where async lifetime errors are being a nuisance ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions