Skip to content

Commit e903af5

Browse files
committed
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 -->
2 parents 207955c + 471de0c commit e903af5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

book/src/configuration.md

+21
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,24 @@ Note: `custom_inner_attributes` is an unstable feature, so it has to be enabled
100100

101101
Lints that recognize this configuration option can be
102102
found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv)
103+
104+
### Disabling evaluation of certain code
105+
106+
> **Note:** This should only be used in cases where other solutions, like `#[allow(clippy::all)]`, are not sufficient.
107+
108+
Very rarely, you may wish to prevent Clippy from evaluating certain sections of code entirely. You can do this with
109+
[conditional compilation](https://doc.rust-lang.org/reference/conditional-compilation.html) by checking that the
110+
`cargo-clippy` feature is not set. You may need to provide a stub so that the code compiles:
111+
112+
```rust
113+
#[cfg(not(feature = "cargo-clippy"))]
114+
include!(concat!(env!("OUT_DIR"), "/my_big_function-generated.rs"));
115+
116+
#[cfg(feature = "cargo-clippy")]
117+
fn my_big_function(_input: &str) -> Option<MyStruct> {
118+
None
119+
}
120+
```
121+
122+
This feature is not actually part of your crate, so specifying `--all-features` to other tools, e.g. `cargo test
123+
--all-features`, will not disable it.

0 commit comments

Comments
 (0)