diff --git a/README.md b/README.md index 8bccd040c1f9..24499f021f46 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,24 @@ That includes warnings found by rustc (e.g. `dead_code`, etc.). If you want to a an error for Clippy warnings, use `#![deny(clippy::all)]` in your code or `-D clippy::all` on the command line. (You can swap `clippy::all` with the specific lint category you are targeting.) +Alternatively, since Cargo 1.97, you can use the [`build.warnings`] config option: + +```toml +# .cargo/config.toml +[build] +warnings = "deny" +``` + +Or via environment variable: + +```bash +CARGO_BUILD_WARNINGS=deny cargo clippy +``` + +Unlike `-Dwarnings`, this does not invalidate build caches and only affects lint warnings. + +[`build.warnings`]: https://doc.rust-lang.org/cargo/reference/config.html#buildwarnings + ## Configuration ### Allowing/denying lints diff --git a/book/src/usage.md b/book/src/usage.md index 23edf6c2abaa..99fdb01cd538 100644 --- a/book/src/usage.md +++ b/book/src/usage.md @@ -47,6 +47,24 @@ cargo clippy -- -Dwarnings > are found in your code. That includes warnings found by rustc (e.g. > `dead_code`, etc.). +Alternatively, since Cargo 1.97, you can use the [`build.warnings`] config option: + +```toml +# .cargo/config.toml +[build] +warnings = "deny" +``` + +Or via environment variable: + +```bash +CARGO_BUILD_WARNINGS=deny cargo clippy +``` + +Unlike `-Dwarnings`, this does not invalidate build caches and only affects lint warnings. + +[`build.warnings`]: https://doc.rust-lang.org/cargo/reference/config.html#buildwarnings + For more information on configuring lint levels, see the [rustc documentation]. [rustc documentation]: https://doc.rust-lang.org/rustc/lints/levels.html#configuring-warning-levels