Skip to content

Commit 471de0c

Browse files
committed
Document cargo-clippy feature
It is possible to use conditional compilation to prevent Clippy from evaluating certain code. This adds a brief explanation of how to use the feature with conditional compilation, and mentions that generally it’s preferable to use something like `#[allow(clippy::all)]`. Fixes #10220 — Ability to skip files or blocks entirely
1 parent 0f75581 commit 471de0c

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 e
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)