@@ -33,26 +33,29 @@ disallowed-names = ["bar", ".."] # -> ["bar", "foo", "baz", "quux"]
3333To deactivate the "for further information visit * lint-link* " message you can define the ` CLIPPY_DISABLE_DOCS_LINKS `
3434environment variable.
3535
36- ### Allowing/denying lints
36+ ### Allowing/Denying Lints
3737
38- You can add options to your code to ` allow ` / ` warn ` / ` deny ` Clippy lints:
38+ #### Attributes in Code
3939
40- * the whole set of ` Warn ` lints using the ` clippy ` lint group ( ` #![ deny(clippy::all)] ` )
40+ You can add attributes to your code to ` allow ` / ` warn ` / ` deny ` Clippy lints:
4141
42- * all lints using both the ` clippy ` and ` clippy::pedantic ` lint groups (` #![deny(clippy::all)] ` ,
43- ` #![deny(clippy::pedantic)] ` ). Note that ` clippy::pedantic ` contains some very aggressive lints prone to false
44- positives.
42+ * the whole set of ` warn ` -by-default lints using the ` clippy ` lint group (` #![allow(clippy::all)] ` )
43+
44+ * all lints using both the ` clippy ` and ` clippy::pedantic ` lint groups (` #![warn(clippy::all, clippy::pedantic)] ` . Note
45+ that ` clippy::pedantic ` contains some very aggressive lints prone to false positives.
4546
4647* only some lints (` #![deny(clippy::single_match, clippy::box_vec)] ` , etc.)
4748
4849* ` allow ` /` warn ` /` deny ` can be limited to a single function or module using ` #[allow(...)] ` , etc.
4950
5051Note: ` allow ` means to suppress the lint for your code. With ` warn ` the lint will only emit a warning, while with ` deny `
51- the lint will emit an error, when triggering for your code. An error causes clippy to exit with an error code, so is
52- useful in scripts like CI/CD.
52+ the lint will emit an error, when triggering for your code. An error causes Clippy to exit with an error code, so is
53+ most useful in scripts used in CI/CD.
54+
55+ #### Command Line Flags
5356
54- If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra
55- flags to Clippy during the run:
57+ If you do not want to include your lint levels in the code, you can globally enable/disable lints by passing extra flags
58+ to Clippy during the run:
5659
5760To allow ` lint_name ` , run
5861
@@ -66,19 +69,33 @@ And to warn on `lint_name`, run
6669cargo clippy -- -W clippy::lint_name
6770```
6871
69- This also works with lint groups. For example, you can run Clippy with warnings for all lints enabled:
72+ This also works with lint groups. For example, you can run Clippy with warnings for all pedantic lints enabled:
7073
7174``` terminal
7275cargo clippy -- -W clippy::pedantic
7376```
7477
75- If you care only about a single lint , you can allow all others and then explicitly warn on the lint(s) you are
78+ If you care only about a certain lints , you can allow all others and then explicitly warn on the lints you are
7679interested in:
7780
7881``` terminal
7982cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
8083```
8184
85+ #### Lints Section in ` Cargo.toml `
86+
87+ Finally, lints can be allowed/denied using [ the lints
88+ section] ( https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section ) ) in the ` Cargo.toml ` file:
89+
90+ To deny ` clippy::enum_glob_use ` , put the following in the ` Cargo.toml ` :
91+
92+ ``` toml
93+ [lints .clippy ]
94+ enum_glob_use = " deny"
95+ ```
96+
97+ For more details and options, refer to the Cargo documentation.
98+
8299### Specifying the minimum supported Rust version
83100
84101Projects that intend to support old versions of Rust can disable lints pertaining to newer features by specifying the
@@ -113,17 +130,14 @@ found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv)
113130
114131Very rarely, you may wish to prevent Clippy from evaluating certain sections of code entirely. You can do this with
115132[ conditional compilation] ( https://doc.rust-lang.org/reference/conditional-compilation.html ) by checking that the
116- ` cargo- clippy` feature is not set. You may need to provide a stub so that the code compiles:
133+ ` clippy ` cfg is not set. You may need to provide a stub so that the code compiles:
117134
118135``` rust
119- #[cfg(not(feature = " cargo- clippy" ) )]
136+ #[cfg(not(clippy)]
120137include! (concat! (env! (" OUT_DIR" ), " /my_big_function-generated.rs" ));
121138
122- #[cfg(feature = " cargo- clippy" )]
139+ #[cfg(clippy)]
123140fn my_big_function (_input : & str ) -> Option <MyStruct > {
124141 None
125142}
126143```
127-
128- This feature is not actually part of your crate, so specifying ` --all-features ` to other tools, e.g. `cargo test
129- --all-features`, will not disable it.
0 commit comments