You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+53-46Lines changed: 53 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -16,52 +16,41 @@ Table of contents:
16
16
17
17
## Usage
18
18
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
+
19
24
As a general rule clippy will only work with the *latest* Rust nightly for now.
20
25
21
-
### As a Compiler Plugin
26
+
### Optional dependency
22
27
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:
26
29
27
-
Add in your `Cargo.toml`:
30
+
In your `Cargo.toml`:
28
31
29
32
```toml
30
33
[dependencies]
31
-
clippy = "*"
32
-
```
34
+
clippy = {version = "*", optional = true}
33
35
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
+
```
36
39
37
-
Sample `main.rs`:
40
+
And, in your `main.rs` or `lib.rs`:
38
41
39
42
```rust
40
-
#![feature(plugin)]
41
-
42
-
#![plugin(clippy)]
43
-
43
+
#![cfg_attr(feature="clippy", feature(plugin))]
44
44
45
-
fnmain(){
46
-
letx=Some(1u8);
47
-
matchx {
48
-
Some(y) =>println!("{:?}", y),
49
-
_=> ()
50
-
}
51
-
}
45
+
#![cfg_attr(feature="clippy", plugin(clippy))]
52
46
```
53
47
54
-
Produces this warning:
48
+
Then build by enabling the feature: `cargo build --features "clippy"`
55
49
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:
(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
0 commit comments