Skip to content

Commit 409b8e7

Browse files
committed
Revert "Revert "Automatically defines the clippy feature""
This reverts commit e4dceef.
1 parent 4923415 commit 409b8e7

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

CHANGELOG.md

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

4+
## 0.0.97 — 2016-10-24
5+
* For convenience, `cargo clippy` defines a `cargo-clippy` feature. This was
6+
previously added for a short time under the name `clippy` but removed for
7+
compatibility.
8+
* `cargo clippy --help` is more helping (and less helpful :smile:)
9+
410
## 0.0.96 — 2016-10-22
511
* Rustup to *rustc 1.14.0-nightly (f09420685 2016-10-20)*
612
* New lint: [`iter_skip_next`]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ You can add options to `allow`/`warn`/`deny`:
163163

164164
Note: `deny` produces errors instead of warnings.
165165

166+
For convenience, `cargo clippy` automatically defines a `cargo-clippy`
167+
features. This lets you set lints level and compile with or without clippy
168+
transparently:
169+
170+
```rust
171+
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
172+
```
173+
166174
## Link with clippy service
167175

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

src/main.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
111111

112112
use std::path::Path;
113113

114-
const CARGO_CLIPPY_HELP: &str = "\
115-
Checks a package to catch common mistakes and improve your Rust code.
114+
const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
116115
117116
Usage:
118117
cargo clippy [options] [--] [<opts>...]
@@ -129,8 +128,13 @@ one of:
129128
-W --warn OPT Set lint warnings
130129
-A --allow OPT Set lint allowed
131130
-D --deny OPT Set lint denied
132-
-F --forbid OPT Set lint forbidden\
133-
";
131+
-F --forbid OPT Set lint forbidden
132+
133+
The feature `cargo-clippy` is automatically defined for convinence. You can use
134+
it to allow or deny lints, eg.:
135+
136+
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
137+
"#;
134138

135139
pub fn main() {
136140
use std::env;
@@ -213,13 +217,16 @@ pub fn main() {
213217

214218
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
215219
// without having to pass --sysroot or anything
216-
let args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
220+
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
217221
env::args().collect()
218222
} else {
219223
env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
220224
};
225+
221226
// this check ensures that dependencies are built but not linted and the final crate is
222227
// linted but not built
228+
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
229+
223230
let mut ccc = ClippyCompilerCalls::new(env::args().any(|s| s == "-Zno-trans"));
224231
let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None);
225232

@@ -251,6 +258,8 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
251258
args.push(String::from("--sysroot"));
252259
args.push(sysroot.to_owned());
253260
args.push("-Zno-trans".to_owned());
261+
args.push("--cfg".to_owned());
262+
args.push(r#"feature="cargo-clippy""#.to_owned());
254263

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

0 commit comments

Comments
 (0)