@@ -140,18 +140,27 @@ before_script:
140140script :
141141 - cargo clippy
142142 # if you want the build job to fail when encountering warnings, use
143- - cargo clippy -- -D warnings
143+ - CARGO_BUILD_WARNINGS=deny cargo clippy
144144 # in order to also check tests and non-default crate features, use
145- - cargo clippy --all-targets --all-features -- -D warnings
145+ - CARGO_BUILD_WARNINGS=deny cargo clippy --all-targets --all-features
146146 - cargo test
147147 # etc.
148148```
149149
150- Note that adding ` -D warnings ` will cause your build to fail if ** any** warnings are found in your code.
150+ Note that setting ` CARGO_BUILD_WARNINGS=deny ` will cause your build to fail if ** any** warnings are found in your code.
151151That includes warnings found by rustc (e.g. ` dead_code ` , etc.). If you want to avoid this and only cause
152152an error for Clippy warnings, use ` #![deny(clippy::all)] ` in your code or ` -D clippy::all ` on the command
153153line. (You can swap ` clippy::all ` with the specific lint category you are targeting.)
154154
155+ Also note that before Cargo 1.97, the usual way to deny all warnings was by using ` -D warnings ` :
156+
157+ ``` shell
158+ cargo clippy -- -D warnings
159+ ```
160+
161+ However, [ ` CARGO_BUILD_WARNINGS ` ] has the benefit of not invalidating build caches,
162+ and is thus to be preferred going forward.
163+
155164## Configuration
156165
157166### Allowing/denying lints
@@ -286,3 +295,5 @@ option. Files in the project may not be
286295copied, modified, or distributed except according to those terms.
287296
288297<!-- REUSE-IgnoreEnd -->
298+
299+ [ `CARGO_BUILD_WARNINGS` ] : https://doc.rust-lang.org/cargo/reference/config.html#buildwarnings
0 commit comments