rust - 如何为单行/ block 禁用 clippy lint?

标签 rust rust-clippy

<分区>

我得到一些像这样的 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")?我觉得一定有,但我在文档中找不到任何这样做的例子。

最佳答案

docs说明您可以允许或拒绝 lints。

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

而且,如果您想禁用所有 1 个:

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

1:clippy:all 实际上不允许所有 lints,而是正确性 包含的所有内容,可疑stylecomplexitycargoperf。这意味着没有 pedanticnursery lints..

关于rust - 如何为单行/ block 禁用 clippy lint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55402812/

相关文章:

rust - 如何防止 Cargo Clippy 分析生成的 Prost 文件

linux - 使用 Cargo 构建 openssl crate 的问题

java - Java 可以在没有 GC 的情况下运行吗

rust - 如何有条件地链接迭代器?

rust - 引用 Rust 中 impl block 中的特征

rust - 为什么 Clippy 建议传递 Arc 作为引用?

rust - 如何打破 Rust 中的 do-while 样式循环?

rust - Rust 的 clippy 可以自动更正/自动修复吗?

rust - Cargo Clippy 抛出错误 'Question mark operator is useless here' - 建议可以实现吗?