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
A collection of lints to catch common mistakes and improve your Rust code.
8
9
9
10
Table of contents:
10
-
*[Lint list](#lints)
11
-
*[Usage instructions](#usage)
12
-
*[Configuration](#configuration)
13
-
*[*clippy-service*](#link-with-clippy-service)
14
-
*[License](#license)
15
11
16
-
##Lints
12
+
*[Lint list](#lints)
13
+
*[Usage instructions](#usage)
14
+
*[Configuration](#configuration)
15
+
*[*clippy-service*](#link-with-clippy-service)
16
+
*[License](#license)
17
+
18
+
## Lints
19
+
17
20
There are 146 lints included in this crate:
18
21
19
22
name | default | meaning
@@ -27,7 +30,7 @@ name
27
30
[block_in_if_condition_stmt](https://github.com/Manishearth/rust-clippy/wiki#block_in_if_condition_stmt) | warn | avoid complex blocks in conditions, instead move the block higher and bind it with 'let'; e.g: `if { let x = true; x } ...`
28
31
[bool_comparison](https://github.com/Manishearth/rust-clippy/wiki#bool_comparison) | warn | comparing a variable to a boolean, e.g. `if x == true`
29
32
[box_vec](https://github.com/Manishearth/rust-clippy/wiki#box_vec) | warn | usage of `Box<Vec<T>>`, vector elements are already on the heap
30
-
[boxed_local](https://github.com/Manishearth/rust-clippy/wiki#boxed_local) | warn | using Box<T> where unnecessary
33
+
[boxed_local](https://github.com/Manishearth/rust-clippy/wiki#boxed_local) | warn | using `Box<T>` where unnecessary
31
34
[cast_possible_truncation](https://github.com/Manishearth/rust-clippy/wiki#cast_possible_truncation) | allow | casts that may cause truncation of the value, e.g `x as u8` where `x: u32`, or `x as i32` where `x: f32`
32
35
[cast_possible_wrap](https://github.com/Manishearth/rust-clippy/wiki#cast_possible_wrap) | allow | casts that may cause wrapping around the value, e.g `x as i32` where `x: u32` and `x > i32::MAX`
33
36
[cast_precision_loss](https://github.com/Manishearth/rust-clippy/wiki#cast_precision_loss) | allow | casts that cause loss of precision, e.g `x as f32` where `x: u64`
@@ -145,7 +148,7 @@ name
145
148
[transmute_ptr_to_ref](https://github.com/Manishearth/rust-clippy/wiki#transmute_ptr_to_ref) | warn | transmutes from a pointer to a reference type
[type_complexity](https://github.com/Manishearth/rust-clippy/wiki#type_complexity) | warn | usage of very complex types; recommends factoring out parts into `type` definitions
148
-
[unicode_not_nfc](https://github.com/Manishearth/rust-clippy/wiki#unicode_not_nfc) | allow | using a unicode literal not in NFC normal form (see http://www.unicode.org/reports/tr15/ for further information)
151
+
[unicode_not_nfc](https://github.com/Manishearth/rust-clippy/wiki#unicode_not_nfc) | allow | using a unicode literal not in NFC normal form (see [unicode tr15](http://www.unicode.org/reports/tr15/) for further information)
149
152
[unit_cmp](https://github.com/Manishearth/rust-clippy/wiki#unit_cmp) | warn | comparing unit values (which is always `true` or `false`, respectively)
150
153
[unnecessary_mut_passed](https://github.com/Manishearth/rust-clippy/wiki#unnecessary_mut_passed) | warn | an argument is passed as a mutable reference although the function/method only demands an immutable reference
151
154
[unneeded_field_pattern](https://github.com/Manishearth/rust-clippy/wiki#unneeded_field_pattern) | warn | Struct fields are bound to a wildcard instead of using `..`
@@ -167,19 +170,25 @@ name
167
170
168
171
More to come, please [file an issue](https://github.com/Manishearth/rust-clippy/issues) if you have ideas!
169
172
170
-
##Usage
173
+
##Usage
171
174
172
-
Compiler plugins are highly unstable and will only work with a nightly Rust for now. Since stable Rust is backwards compatible, you should be able to compile your stable programs with nightly Rust with clippy plugged in to circumvent this.
175
+
Compiler plugins are highly unstable and will only work with a nightly Rust for now.
176
+
Since stable Rust is backwards compatible, you should be able to compile
177
+
your stable programs with nightly Rust with clippy plugged in to circumvent
178
+
this.
173
179
174
180
Add in your `Cargo.toml`:
181
+
175
182
```toml
176
183
[dependencies]
177
184
clippy = "*"
178
185
```
179
186
180
-
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top of your crate entry point (`main.rs` or `lib.rs`).
187
+
You then need to add `#![feature(plugin)]` and `#![plugin(clippy)]` to the top
188
+
of your crate entry point (`main.rs` or `lib.rs`).
181
189
182
190
Sample `main.rs`:
191
+
183
192
```rust
184
193
#![feature(plugin)]
185
194
@@ -196,7 +205,8 @@ fn main(){
196
205
```
197
206
198
207
Produces this warning:
199
-
```
208
+
209
+
```terminal
200
210
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
An alternate way to use clippy is by compiling and using [`cargo clippy`](https://github.com/arcnmx/cargo-clippy), a custom cargo subcommand that runs clippy on a given project.
219
+
An alternate way to use clippy is by compiling and using [`cargo clippy`](https://github.com/arcnmx/cargo-clippy),
220
+
a custom cargo subcommand that runs clippy on a given project.
211
221
212
222
You can add options to `allow`/`warn`/`deny`:
213
-
- the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
214
-
- all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`, `#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive lints prone to false positives.
215
-
- only some lints (`#![deny(single_match, box_vec)]`, etc)
216
-
-`allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
223
+
224
+
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
225
+
226
+
* all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`,
227
+
`#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive
228
+
lints prone to false positives.
229
+
230
+
* only some lints (`#![deny(single_match, box_vec)]`, etc)
231
+
232
+
*`allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
217
233
218
234
Note: `deny` produces errors instead of warnings
219
235
220
236
To have cargo compile your crate with clippy without needing `#![plugin(clippy)]`
*[Note](https://github.com/Manishearth/rust-clippy/wiki#a-word-of-warning):* Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
Be sure that clippy was compiled with the same version of rustc that cargo invokes here!
228
245
229
246
If you want to make clippy an optional dependency, you can do the following:
230
247
231
248
In your `Cargo.toml`:
249
+
232
250
```toml
233
251
[dependencies]
234
252
clippy = {version = "*", optional = true}
@@ -245,9 +263,13 @@ And, in your `main.rs` or `lib.rs`:
245
263
#![cfg_attr(feature="clippy", plugin(clippy))]
246
264
```
247
265
248
-
Instead of adding the `cfg_attr` attributes you can also run clippy on demand: `cargo rustc --features clippy -- -Z no-trans -Z extra-plugins=clippy` (the `-Z no trans`, while not neccessary, will stop the compilation process after typechecking (and lints) have completed, which can significantly reduce the runtime).
266
+
Instead of adding the `cfg_attr` attributes you can also run clippy on demand:
`clippy-service` is a rust web initiative providing `rust-clippy` as a web service.
268
292
269
-
Both projects are independent and maintained by different people (even if some `clippy-service`'s contributions are authored by some `rust-clippy` members).
293
+
Both projects are independent and maintained by different people
294
+
(even if some `clippy-service`'s contributions are authored by some `rust-clippy` members).
270
295
271
296
You can check out this great service at [clippy.bashy.io](https://clippy.bashy.io/).
272
297
273
-
##License
274
-
Licensed under [MPL](https://www.mozilla.org/MPL/2.0/). If you're having issues with the license, let me know and I'll try to change it to something more permissive.
298
+
## License
299
+
300
+
Licensed under [MPL](https://www.mozilla.org/MPL/2.0/).
301
+
If you're having issues with the license, let me know and I'll try to change it to something more permissive.
0 commit comments