snippetrustMajor
How to disable a clippy lint for a single line / block?
Viewed 0 times
howdisablelinelintforsingleblockclippy
Problem
I am getting some Clippy lints that look like this:
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
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(self, mapper: F) -> Vec
| ^^^^
|
= 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.
And ,if you want to disable all 1 of them:
1:
#[allow(clippy::wrong_self_convention)] pub fn to_vec_sorted(self, mapper: F) -> VecAnd ,if you want to disable all 1 of them:
#[allow(clippy::all)] pub fn to_vec_sorted(self, mapper: F) -> Vec1:
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..Code Snippets
#[allow(clippy::wrong_self_convention)] pub fn to_vec_sorted<U, F>(self, mapper: F) -> Vec<U>#[allow(clippy::all)] pub fn to_vec_sorted<U, F>(self, mapper: F) -> Vec<U>Context
Stack Overflow Q#55402812, score: 99
Revisions (0)
No revisions yet.