Skip to content

Commit d7ba66b

Browse files
committed
Automatically defines the clippy feature
1 parent 94cc344 commit d7ba66b

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.76 — TBD
5+
* `cargo clippy` now automatically defines the `clippy` feature
6+
47
## 0.0.75 — 2016-06-08
58
* Rustup to *rustc 1.11.0-nightly (763f9234b 2016-06-06)*
69

README.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,22 +245,6 @@ similar crates.
245245
SYSROOT=/path/to/rustc/sysroot cargo install clippy
246246
```
247247

248-
### Configuring clippy
249-
250-
You can add options to `allow`/`warn`/`deny`:
251-
252-
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
253-
254-
* all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`,
255-
`#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive
256-
lints prone to false positives.
257-
258-
* only some lints (`#![deny(single_match, box_vec)]`, etc)
259-
260-
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
261-
262-
Note: `deny` produces errors instead of warnings
263-
264248
### Running clippy from the command line without installing
265249

266250
To have cargo compile your crate with clippy without needing `#![plugin(clippy)]`
@@ -321,6 +305,29 @@ You can also specify the path to the configuration file with:
321305
To deactivate the “for further information visit *wiki-link*” message you can
322306
define the `CLIPPY_DISABLE_WIKI_LINKS` environment variable.
323307

308+
### Allowing/denying lints
309+
310+
You can add options to `allow`/`warn`/`deny`:
311+
312+
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`)
313+
314+
* all lints using both the `clippy` and `clippy_pedantic` lint groups (`#![deny(clippy)]`,
315+
`#![deny(clippy_pedantic)]`). Note that `clippy_pedantic` contains some very aggressive
316+
lints prone to false positives.
317+
318+
* only some lints (`#![deny(single_match, box_vec)]`, etc)
319+
320+
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
321+
322+
Note: `deny` produces errors instead of warnings.
323+
324+
For convenience, `cargo clippy` automatically defines a `clippy` features. This
325+
lets you set lints level and compile with or without clippy transparently:
326+
327+
```rust
328+
#[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
329+
```
330+
324331
## Link with clippy service
325332

326333
`clippy-service` is a rust web initiative providing `rust-clippy` as a web service.

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ pub fn main() {
141141
}
142142
}
143143
} else {
144-
let args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
144+
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
145145
env::args().collect()
146146
} else {
147147
env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
148148
};
149+
150+
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="clippy""#.to_owned()]);
151+
149152
let (result, _) = rustc_driver::run_compiler(&args, &mut ClippyCompilerCalls::new());
150153

151154
if let Err(err_count) = result {
@@ -174,6 +177,8 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
174177
args.push(String::from("--sysroot"));
175178
args.push(sysroot.to_owned());
176179
args.push("-Zno-trans".to_owned());
180+
args.push("--cfg".to_owned());
181+
args.push(r#"feature="clippy""#.to_owned());
177182

178183
let path = std::env::current_exe().expect("current executable path invalid");
179184
let exit_status = std::process::Command::new("cargo")

0 commit comments

Comments
 (0)