简体   繁体   English

Rust 的 clippy 可以进行自动更正/自动修复吗?

[英]Can Rust's clippy do autocorrection / autofix?

Is it possible to run cargo clippy with an option so it will fix warnings automatically?是否可以使用选项运行cargo clippy以便自动修复警告?

From the help message, it does not look like this option is supported at the moment.从帮助消息来看,目前似乎不支持此选项。

cargo fix can already apply some suggestions deriving from rustc 's errors and warnings. cargo fix已经可以应用一些来自rustc的错误和警告的建议。

In nightly builds, since Rust 1.38 — that is, since Rust 1.40-nightly — you can use cargo fix --clippy to apply certain suggestions from Clippy too. 每晚构建中,由于Rust 1.38 (即Rust 1.40每晚)以来,您也可以使用cargo fix --clippy来应用来自Clippy的某些建议。

If you are using a stable version of the Rust toolchain, you can opt-in to use a nightly build for just one command, by using +nightly to override the toolchain: 如果您使用的是Rust工具链的稳定版本,则可以选择使用夜间构建来仅使用一个命令,方法是使用+nightly覆盖工具链:

cargo +nightly fix --clippy -Z unstable-options

截至 2021 年 6 月,自动修复功能已稳定,您可以使用以下命令应用更改

cargo clippy --fix

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Rust 中使用 clippy 如何禁用 clippy::struct-excessive-bools? - In Rust using clippy how can I disable clippy::struct-excessive-bools? 如何修复Clippy的needless_range_loop用于在具有偏移的切片之间复制的循环? - How do I fix Clippy's needless_range_loop for loops that copy between slices with an offset? 我可以在 Rust 中执行 C++ 的 SFINAE 吗? - Can I do C++'s SFINAE in Rust? 使用 Substrate 的 decl_event 时,如何隐藏 Clippy 关于“不需要的单元表达式”的警告? - How do I hide the warning from Clippy about "unneeded unit expression" when using Substrate's decl_event? 如何修复针对 or_insert / or_insert_with 的 clippy::or_fun_call 的 Clippy 警告? - How do I fix the Clippy warning for clippy::or_fun_call for or_insert / or_insert_with? 如何删除 Rust clippy 警告`考虑使用`vec:[]`宏:`let mut https: Vec<u8> = vec.[.;];`</u8> - How to remove Rust clippy warning `consider using the `vec![]` macro: `let mut https: Vec<u8> = vec![..];` 如何为工作区中的所有板条箱共享 Clippy 配置? - How can I have a shared Clippy configuration for all the crates in a workspace? 可以在Rust中模拟或使用Python的isinstance吗? - Can Python's isinstance be emulated or used in Rust? 如何抑制来自宏的 Clippy 警告? - How can I suppress a Clippy warning originating from a macro? 如何定义可以执行按位运算的整数上通用的Rust函数? - How to define Rust function that's generic on integers that can do bitwise operations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM