Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 791
Richard Rast Avatar asked Mar 28 '19 16:03

Richard Rast


People also ask

What is Clippy Rust?

Clippy is a tool for catching common mistakes in Rust code and improving it. An expansive list of lints and the justification can be found in their documentation.

Does cargo Clippy run cargo check?

cargo clippy runs Clippy, while cargo check only tries to compile with rustc. cargo clippy should give all errors and warnings of cargo check combined with Clippy specific warnings.


1 Answers

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 of them:

#[allow(clippy::all)] pub fn to_vec_sorted<U, F>(self, mapper: F) -> Vec<U> 
like image 54
Ealhad Avatar answered Sep 20 '22 15:09

Ealhad