Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual_async_fn false positive #5765

Closed
Seeker14491 opened this issue Jul 4, 2020 · 2 comments · Fixed by #5859
Closed

manual_async_fn false positive #5765

Seeker14491 opened this issue Jul 4, 2020 · 2 comments · Fixed by #5859
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Seeker14491
Copy link

The following code triggers the manual_async_fn lint:

use std::future::Future;

struct A;

impl A {
    fn f(&self) -> impl Future<Output = ()> {
        async {}
    }
}

fn main() {
    let _future = {
        let a = A;
        a.f()
    };
}

However, applying the suggestion of using an async fn causes the code to stop compiling:

error[E0597]: `a` does not live long enough
  --> src\main.rs:14:9
   |
12 |     let _future = {
   |         ------- borrow later stored here
13 |         let a = A;
14 |         a.f()
   |         ^ borrowed value does not live long enough
15 |     };
   |     - `a` dropped here while still borrowed

This is due to async fn implicitly capturing the lifetime of &self in the returned future, while the impl Future syntax does not.

Meta

  • cargo clippy -V: clippy 0.0.212 (50fc24d 2020-06-25)
  • rustc -Vv:
    rustc 1.46.0-nightly (50fc24d8a 2020-06-25)
    binary: rustc
    commit-hash: 50fc24d8a172a853b5dfe40702d6550e3b8562ba
    commit-date: 2020-06-25
    host: x86_64-pc-windows-msvc
    release: 1.46.0-nightly
    LLVM version: 10.0
    
@Seeker14491 Seeker14491 added the C-bug Category: Clippy is not doing the correct thing label Jul 4, 2020
@ebroto
Copy link
Member

ebroto commented Jul 4, 2020

To be consistent with async fn, we should check that the returned future captures all the input lifetimes, or that there are no input lifetimes. See here.

I will work on fixing this in the coming days.

@ebroto
Copy link
Member

ebroto commented Aug 2, 2020

So holidays and other stuff came and I could not dedicate a lot of time to clippy until now. Sorry for the delay!

@bors bors closed this as completed in 2eab060 Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants