False alert from clippy? (lifetime elision for &str)

Hi,

I have this signatue:

async fn process_draw_args<'a>(
    ctx: &Context,
    msg: &Message,
    args: &'a Args,
) -> Result<(u32, Option<&'a str>, bool), serenity::Error> {
// ...
}

and clippy is complaining about it:

warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
   --> src\discord\cards_cmd.rs:274:1
    |
274 | / async fn process_draw_args<'a>(
275 | |     ctx: &Context,
276 | |     msg: &Message,
277 | |     args: &'a Args,
278 | | ) -> Result<(u32, Option<&'a str>, bool), serenity::Error> {
    | |__________________________________________________________^
    |
    = note: `#[warn(clippy::needless_lifetimes)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes  

But obviously, I can't remove the lifetime from &'a str and I tried to replace 'a by '_ and it's worse ^^'

So can I assume it's a false alarm from clippy?

Yes, this is a false positive. The relevant issue is Incorrect lint: needless_lifetimes · Issue #5787 · rust-lang/rust-clippy · GitHub. I would recommend placing an #[allow(clippy::needless_lifetimes)] right above the function with a comment that has a link to the bug.

2 Likes