如何为单行/块禁用clippy lint? [重复]

问题描述 投票:3回答:1

这个问题在这里已有答案:

我得到一些看起来像这样的Clippy lints:

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

我没有问题处理这个lint,我只是选择它,因为它没有显示任何专有代码。假设我有一个非常好的理由为什么我需要以这种方式命名函数,并且Clippy已集成到我的CI中,因此我需要零Clippy错误/警告。

有没有办法为特定的行或代码块禁用Clippy lint,类似于Java中的@SuppressWarnings("whatever")?我觉得必须有,但我在文档中找不到任何这样做的例子。

rust clippy
1个回答
3
投票

docs状态你可以允许或否认lints。

#[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>
© www.soinside.com 2019 - 2024. All rights reserved.