Skip to content

Commit 5a415f6

Browse files
author
Daniel S Poulin
authored
Clarify recco to install as a soft dependency
On IRC it was mentioned that clippy is not meant to be installed as a hard dependency. As it was, the README placed the hard dependency instructions first and did not mention the recommendation, misleading users into making it a hard dependency. A quick survey of the dependent crates on crates.io reveals the reach of this issue.
1 parent 276e85b commit 5a415f6

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

README.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,41 @@ Table of contents:
1717

1818
## Usage
1919

20+
Since this is a tool for helping the developer of a library or application
21+
write better code, it is recommended to include clippy as an optional
22+
dependency.
23+
2024
As a general rule clippy will only work with the *latest* Rust nightly for now.
2125

26+
### Optional dependency
27+
28+
If you want to make clippy an optional dependency, you can do the following:
29+
30+
In your `Cargo.toml`:
31+
32+
```toml
33+
[dependencies]
34+
clippy = {version = "*", optional = true}
35+
36+
[features]
37+
default = []
38+
```
39+
40+
And, in your `main.rs` or `lib.rs`:
41+
42+
```rust
43+
#![cfg_attr(feature="clippy", feature(plugin))]
44+
45+
#![cfg_attr(feature="clippy", plugin(clippy))]
46+
```
47+
48+
Then build by enabling the feature: `cargo build --features "clippy"`
49+
50+
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
51+
`cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy`
52+
(the `-Z no trans`, while not neccessary, will stop the compilation process after
53+
typechecking (and lints) have completed, which can significantly reduce the runtime).
54+
2255
### As a Compiler Plugin
2356

2457
Since stable Rust is backwards compatible, you should be able to
@@ -97,34 +130,6 @@ cargo rustc -- -L /path/to/clippy_so -Z extra-plugins=clippy
97130
*[Note](https://github.com/Manishearth/rust-clippy/wiki#a-word-of-warning):*
98131
Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
99132

100-
### Optional dependency
101-
102-
If you want to make clippy an optional dependency, you can do the following:
103-
104-
In your `Cargo.toml`:
105-
106-
```toml
107-
[dependencies]
108-
clippy = {version = "*", optional = true}
109-
110-
[features]
111-
default = []
112-
```
113-
114-
And, in your `main.rs` or `lib.rs`:
115-
116-
```rust
117-
#![cfg_attr(feature="clippy", feature(plugin))]
118-
119-
#![cfg_attr(feature="clippy", plugin(clippy))]
120-
```
121-
122-
Then build by enabling the feature: `cargo build --features "clippy"`
123-
124-
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
125-
`cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy`
126-
(the `-Z no trans`, while not neccessary, will stop the compilation process after
127-
typechecking (and lints) have completed, which can significantly reduce the runtime).
128133

129134
## Configuration
130135

0 commit comments

Comments
 (0)