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

False positive for needless_lifetimes (possibly due to async?) #4746

Closed
tmccombs opened this issue Oct 28, 2019 · 2 comments
Closed

False positive for needless_lifetimes (possibly due to async?) #4746

tmccombs opened this issue Oct 28, 2019 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing T-async-await Type: Issues related to async/await

Comments

@tmccombs
Copy link

tmccombs commented Oct 28, 2019

Output of cargo clippy -V:

clippy 0.0.212 (4e7e71b 2019-10-11)

I have a method that looks like this:

    pub async fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
        let mutex = guard_lock(&guard);

        self.await_notify(guard).await;

        mutex.lock().await
    }

Clippy flags the signature for needless lifetimes. However, replacing the 'a lifteime with the anonymous '_ as suggested, results in a lifetime mismatch error, because the lifetime of the return value comes from the guard argument, not self. As far as I understand, lifetimes cannot be elided here.

@tmccombs tmccombs changed the title Fals positive for needless_lifetimes (possibly due to async?) False positive for needless_lifetimes (possibly due to async?) Oct 28, 2019
@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing T-async-await Type: Issues related to async/await labels Oct 28, 2019
@flip1995
Copy link
Member

flip1995 commented Oct 28, 2019

Reproducer: Playground

use std::sync::MutexGuard;

struct Foo;

impl Foo {
    // doesn't get linted without async
    pub async fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
        guard
    }
}

@flip1995
Copy link
Member

flip1995 commented Dec 4, 2020

Closing as duplicate of #5787, which has some more examples

@flip1995 flip1995 closed this as completed Dec 4, 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 T-async-await Type: Issues related to async/await
Projects
None yet
Development

No branches or pull requests

2 participants