Skip to content

Incorrect lint: needless_lifetimes #5787

Closed
@vmalloc

Description

@vmalloc

I tried this code:

pub async fn send<'a>(&self, client: &'a Client) -> Result<Request<'a>> {
       ...
        Ok(Request::new(client, self.request_id))
    }

Clippy complains that this violates "needless_lifetimes". However trying to elide them cannot succeed due to the &self reference:

pub async fn send(&self, client: &Client) -> Result<Request<'_>> {
       ...
        Ok(Request::new(client, self.request_id))
    }

Fails:

pub async fn send<'a>(&self, client: &Client) -> Result<Request<'_>> {
   |                           -----                      -------------------------
   |                           |
   |                           this parameter and the return type are declared with different lifetimes...
...
Ok(Request::new(client, self.order_id))
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `client` is returned here

I'm not sure if there is actually an option for elision here at all...

Meta

  • cargo clippy -V: clippy 0.0.212 (bb37a0f 2020-06-16)
  • rustc -Vv:
rustc 1.44.1 (c7087fe00 2020-06-17)
binary: rustc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-apple-darwin
release: 1.44.1
LLVM version: 9.0

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-async-awaitType: Issues related to async/await

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions