Revert "Revert "Automatically defines the `clippy` feature""

This reverts commit e4dceef7e7.
This commit is contained in:
mcarton 2016-10-24 16:04:00 +02:00
parent 4923415930
commit 409b8e7343
No known key found for this signature in database
GPG Key ID: 5E427C794CBA45E8
3 changed files with 28 additions and 5 deletions

View File

@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.
## 0.0.97 — 2016-10-24
* For convenience, `cargo clippy` defines a `cargo-clippy` feature. This was
previously added for a short time under the name `clippy` but removed for
compatibility.
* `cargo clippy --help` is more helping (and less helpful :smile:)
## 0.0.96 — 2016-10-22
* Rustup to *rustc 1.14.0-nightly (f09420685 2016-10-20)*
* New lint: [`iter_skip_next`]

View File

@ -163,6 +163,14 @@ You can add options to `allow`/`warn`/`deny`:
Note: `deny` produces errors instead of warnings.
For convenience, `cargo clippy` automatically defines a `cargo-clippy`
features. This lets you set lints level and compile with or without clippy
transparently:
```rust
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
```
## Link with clippy service
`clippy-service` is a rust web initiative providing `rust-clippy` as a web service.

View File

@ -111,8 +111,7 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
use std::path::Path;
const CARGO_CLIPPY_HELP: &str = "\
Checks a package to catch common mistakes and improve your Rust code.
const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
Usage:
cargo clippy [options] [--] [<opts>...]
@ -129,8 +128,13 @@ one of:
-W --warn OPT Set lint warnings
-A --allow OPT Set lint allowed
-D --deny OPT Set lint denied
-F --forbid OPT Set lint forbidden\
";
-F --forbid OPT Set lint forbidden
The feature `cargo-clippy` is automatically defined for convinence. You can use
it to allow or deny lints, eg.:
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
"#;
pub fn main() {
use std::env;
@ -213,13 +217,16 @@ pub fn main() {
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
// without having to pass --sysroot or anything
let args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
env::args().collect()
} else {
env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
};
// this check ensures that dependencies are built but not linted and the final crate is
// linted but not built
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
let mut ccc = ClippyCompilerCalls::new(env::args().any(|s| s == "-Zno-trans"));
let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None);
@ -251,6 +258,8 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
args.push(String::from("--sysroot"));
args.push(sysroot.to_owned());
args.push("-Zno-trans".to_owned());
args.push("--cfg".to_owned());
args.push(r#"feature="cargo-clippy""#.to_owned());
let path = std::env::current_exe().expect("current executable path invalid");
let exit_status = std::process::Command::new("cargo")