Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Rust's clippy do autocorrection / autofix?

Is it possible to run cargo clippy with an option so it will fix warnings automatically?

From the help message, it does not look like this option is supported at the moment.

like image 582
Sergey Potapov Avatar asked Dec 07 '18 13:12

Sergey Potapov


People also ask

What does rust clippy do?

The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code.


1 Answers

cargo fix can already apply some suggestions deriving from rustc's errors and warnings.

In nightly builds you can use cargo clippy --fix to apply some suggestions from Clippy. In some older Rust versions, the syntax is reversed: cargo fix --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:

cargo +nightly clippy --fix -Z unstable-options
like image 120
Peter Hall Avatar answered Oct 07 '22 02:10

Peter Hall