Skip to content

Commit cc8c1c0

Browse files
authored
Merge pull request #1345 from EpocSquadron/epocsquadron-documentation
Clarify recco to install as a soft dependency
2 parents d61c7fc + e40cb6a commit cc8c1c0

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed

README.md

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,41 @@ Table of contents:
1616

1717
## Usage
1818

19+
Since this is a tool for helping the developer of a library or application
20+
write better code, it is recommended not to include clippy as a hard dependency.
21+
Options include using it as an optional dependency, as a cargo subcommand, or
22+
as an included feature during build. All of these options are detailed below.
23+
1924
As a general rule clippy will only work with the *latest* Rust nightly for now.
2025

21-
### As a Compiler Plugin
26+
### Optional dependency
2227

23-
Since stable Rust is backwards compatible, you should be able to
24-
compile your stable programs with nightly Rust with clippy plugged in to
25-
circumvent this.
28+
If you want to make clippy an optional dependency, you can do the following:
2629

27-
Add in your `Cargo.toml`:
30+
In your `Cargo.toml`:
2831

2932
```toml
3033
[dependencies]
31-
clippy = "*"
32-
```
34+
clippy = {version = "*", optional = true}
3335

34-
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top
35-
of your crate entry point (`main.rs` or `lib.rs`).
36+
[features]
37+
default = []
38+
```
3639

37-
Sample `main.rs`:
40+
And, in your `main.rs` or `lib.rs`:
3841

3942
```rust
40-
#![feature(plugin)]
41-
42-
#![plugin(clippy)]
43-
43+
#![cfg_attr(feature="clippy", feature(plugin))]
4444

45-
fn main(){
46-
let x = Some(1u8);
47-
match x {
48-
Some(y) => println!("{:?}", y),
49-
_ => ()
50-
}
51-
}
45+
#![cfg_attr(feature="clippy", plugin(clippy))]
5246
```
5347

54-
Produces this warning:
48+
Then build by enabling the feature: `cargo build --features "clippy"`
5549

56-
```terminal
57-
src/main.rs:8:5: 11:6 warning: you seem to be trying to use match for destructuring a single type. Consider using `if let`, #[warn(single_match)] on by default
58-
src/main.rs:8 match x {
59-
src/main.rs:9 Some(y) => println!("{:?}", y),
60-
src/main.rs:10 _ => ()
61-
src/main.rs:11 }
62-
src/main.rs:8:5: 11:6 help: Try
63-
if let Some(y) = x { println!("{:?}", y) }
64-
```
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).
6554

6655
### As a cargo subcommand (`cargo clippy`)
6756

@@ -96,34 +85,52 @@ cargo rustc -- -L /path/to/clippy_so -Z extra-plugins=clippy
9685
*[Note](https://github.com/Manishearth/rust-clippy/wiki#a-word-of-warning):*
9786
Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
9887

99-
### Optional dependency
88+
### As a Compiler Plugin
10089

101-
If you want to make clippy an optional dependency, you can do the following:
90+
*Note:* This is not a recommended installation method.
10291

103-
In your `Cargo.toml`:
92+
Since stable Rust is backwards compatible, you should be able to
93+
compile your stable programs with nightly Rust with clippy plugged in to
94+
circumvent this.
95+
96+
Add in your `Cargo.toml`:
10497

10598
```toml
10699
[dependencies]
107-
clippy = {version = "*", optional = true}
108-
109-
[features]
110-
default = []
100+
clippy = "*"
111101
```
112102

113-
And, in your `main.rs` or `lib.rs`:
103+
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top
104+
of your crate entry point (`main.rs` or `lib.rs`).
105+
106+
Sample `main.rs`:
114107

115108
```rust
116-
#![cfg_attr(feature="clippy", feature(plugin))]
109+
#![feature(plugin)]
117110

118-
#![cfg_attr(feature="clippy", plugin(clippy))]
111+
#![plugin(clippy)]
112+
113+
114+
fn main(){
115+
let x = Some(1u8);
116+
match x {
117+
Some(y) => println!("{:?}", y),
118+
_ => ()
119+
}
120+
}
119121
```
120122

121-
Then build by enabling the feature: `cargo build --features "clippy"`
123+
Produces this warning:
122124

123-
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
124-
`cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy`
125-
(the `-Z no trans`, while not neccessary, will stop the compilation process after
126-
typechecking (and lints) have completed, which can significantly reduce the runtime).
125+
```terminal
126+
src/main.rs:8:5: 11:6 warning: you seem to be trying to use match for destructuring a single type. Consider using `if let`, #[warn(single_match)] on by default
127+
src/main.rs:8 match x {
128+
src/main.rs:9 Some(y) => println!("{:?}", y),
129+
src/main.rs:10 _ => ()
130+
src/main.rs:11 }
131+
src/main.rs:8:5: 11:6 help: Try
132+
if let Some(y) = x { println!("{:?}", y) }
133+
```
127134

128135
## Configuration
129136

0 commit comments

Comments
 (0)