diff options
| author | bors <bors@rust-lang.org> | 2023-04-03 12:12:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-03 12:12:17 +0000 |
| commit | e903af506f2a18978efc02f1407bc3949d479c92 (patch) | |
| tree | 8fa2f0594b2737547203cbe3a634f45d4e6106b5 | |
| parent | 207955cee5708c3a521da9a9a71a46e5deb7445f (diff) | |
| parent | 471de0cb9f7ed11a437d830329050ee419d2ead0 (diff) | |
| download | rust-e903af506f2a18978efc02f1407bc3949d479c92.tar.gz rust-e903af506f2a18978efc02f1407bc3949d479c92.zip | |
Auto merge of #10229 - danielparks:doc-feature-cargo-clippy, r=flip1995
Document `cargo-clippy` feature It is possible to use conditional compilation to prevent Clippy from evaluating certain code at all. Unfortunately, it was no longer documented anywhere. This adds a brief explanation of how to use the feature with conditional compilation, and mentions a few downsides. Fixes #10220 — Ability to skip files or blocks entirely changelog: none <!-- changelog_checked -->
| -rw-r--r-- | book/src/configuration.md | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/book/src/configuration.md b/book/src/configuration.md index 4947d3d1226..1304f6a8c2f 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -100,3 +100,24 @@ Note: `custom_inner_attributes` is an unstable feature, so it has to be enabled Lints that recognize this configuration option can be found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv) + +### Disabling evaluation of certain code + +> **Note:** This should only be used in cases where other solutions, like `#[allow(clippy::all)]`, are not sufficient. + +Very rarely, you may wish to prevent Clippy from evaluating certain sections of code entirely. You can do this with +[conditional compilation](https://doc.rust-lang.org/reference/conditional-compilation.html) by checking that the +`cargo-clippy` feature is not set. You may need to provide a stub so that the code compiles: + +```rust +#[cfg(not(feature = "cargo-clippy"))] +include!(concat!(env!("OUT_DIR"), "/my_big_function-generated.rs")); + +#[cfg(feature = "cargo-clippy")] +fn my_big_function(_input: &str) -> Option<MyStruct> { + None +} +``` + +This feature is not actually part of your crate, so specifying `--all-features` to other tools, e.g. `cargo test +--all-features`, will not disable it. |
