Skip to content

single-use lifetime lint warning on expanded automock #626

Closed
@Rosdf

Description

@Rosdf
#[derive(Debug)]
pub struct MyEr;

#[mockall::automock]
pub trait MyTrait {
    /// # Errors
    ///
    /// some stuff
    fn get<'a>(
        &'a mut self,
        data: i32,
    ) -> Result<&'a str, MyEr>;
}

this code after cargo check produces

warning: lifetime parameter `'a` only used once
  --> src/main.rs:13:12
   |
13 |     fn get<'a>(
   |            ^^
   |            |
   |            this lifetime...
   |            ...is used only here
   |
   = note: requested on the command line with `-W single-use-lifetimes`
help: elide the single-use lifetime
   |
13 -     fn get<'a>(
13 +     fn get<'_>(
   |

there is an easy way out by applying #[allow] on this method, but in my project allow is forbidden in favor of except (clippy::allow_attributes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions