rustrust-clippy

How to disable a clippy lint for a single line / block?


I am getting some Clippy lints that look like this:

warning: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
  --> src/helpers/mod.rs:29:32
   |
29 |     pub fn to_vec_sorted<U, F>(self, mapper: F) -> Vec<U>
   |                                ^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention

I have no problem dealing with this lint, I just picked it because it doesn't show any proprietary code. Suppose I had a really good reason why I needed to name the function this way, and also that Clippy is integrated into my CI, so I need to have zero Clippy errors / warnings.

Is there a way to disable a Clippy lint for a particular line or code block, analogous to @SuppressWarnings("whatever") in Java? I feel like there must be, but I can't find any examples of doing this in the documentation.


Solution

  • The docs state you can allow or deny lints.

    #[allow(clippy::wrong_self_convention)] pub fn to_vec_sorted<U, F>(self, mapper: F) -> Vec<U>
    

    And ,if you want to disable all 1 of them:

    #[allow(clippy::all)] pub fn to_vec_sorted<U, F>(self, mapper: F) -> Vec<U>
    

    1: clippy:all doesn't actually allow all lints, rather everything contained by correctness, suspicious, style, complexity, cargo, and perf. This means no pedantic or nursery lints..