Skip to content

Commit ac34cfa

Browse files
committed
Add blog post about deprecating feature = cargo-clippy
1 parent 2354067 commit ac34cfa

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
layout: post
3+
title: "Clippy: Deprecating `feature = \"cargo-clippy\"`"
4+
author: The Clippy Team
5+
release: true
6+
---
7+
8+
Since Clippy [`v0.0.97`] and before it was shipped with `rustup`, Clippy
9+
implicitly added a `feature = "cargo-clippy"`[^1] when linting your code with
10+
`cargo clippy`.
11+
12+
[^1]: It's likely, that you didn't even know that Clippy implicitly sets this
13+
feature. This is intentional, as we stopped advertising and documenting this
14+
a long time ago.
15+
16+
Back in the day (2016) this was necessary to allow, warn or deny lints with
17+
attributes:
18+
19+
```rust
20+
#[cfg_attr(feature = "cargo-clippy", allow(clippy_lint_name))]
21+
```
22+
23+
Doing this hasn't been necessary for a long time. Today, Clippy users will set
24+
lint levels with tool lint attributes using the `clippy::` prefix:
25+
26+
```rust
27+
#[allow(clippy::lint_name)]
28+
```
29+
30+
The implicit `feature = "cargo-clippy"` has only been kept for backwards
31+
compatibility, but will now be deprecated.
32+
33+
## Alternative
34+
35+
As there is a rare [use case] for conditional compilation depending on Clippy,
36+
we will provide an alternative. So in the future you will be able to use:
37+
38+
```rust
39+
#[cfg(clippy)]
40+
```
41+
42+
## Transitioning
43+
44+
Should you have instances of `feature = "cargo-clippy"` in your code base, you
45+
will see a warning from the new Clippy lint
46+
[`clippy::deprecated_clippy_cfg_attr`][pr-12292]. This lint can automatically fix
47+
your code. So if you should see this lint triggering, just run:
48+
49+
```
50+
cargo clippy --fix -- -Aclippy::all -Wclippy::deprecated_clippy_cfg_attr
51+
```
52+
53+
This will fix all instances in your code.
54+
55+
In addition, check your `.cargo/config` file for:
56+
57+
```toml
58+
[target.'cfg(feature = "cargo-clippy")']
59+
rustflags = ["-Aclippy::..."]
60+
```
61+
62+
This file you have to update yourself, by either changing it to `cfg(clippy)` or
63+
taking this opportunity to transition to [setting lint levels in
64+
`Cargo.toml`][cargo-lints] directly.
65+
66+
## Motivation for Deprecation
67+
68+
There's a plan to stabilize [checking conditional compilation at compile
69+
time][rfc-3013], aka `cargo check -Zcheck-cfg`. If we were to keep `feature =
70+
"cargo-clippy"`, users would start seeing a lot of warnings when running `cargo
71+
clippy`. To work around this, they would have to add a dummy feature to their
72+
`Cargo.toml` in order to silence those warnings:
73+
74+
```toml
75+
[features]
76+
cargo-clippy = []
77+
```
78+
79+
We didn't think this would be user friendly and decided, that we want to
80+
deprecate the implicit `feature = "cargo-clippy"` and replace it with
81+
`cfg(clippy)` instead.
82+
83+
[`v0.0.97`]: https://github.com/rust-lang/rust-clippy/blob/61daf674eaf17f3b504c51f01b4ee63fac47dfcf/CHANGELOG.md?plain=0#0097--2016-11-03
84+
[rfc-3013]: https://github.com/rust-lang/rfcs/pull/3013
85+
[use case]: https://doc.rust-lang.org/clippy/configuration.html#disabling-evaluation-of-certain-code
86+
[pr-12292]: https://github.com/rust-lang/rust-clippy/pull/12292
87+
[cargo-lints]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-lints-section

0 commit comments

Comments
 (0)