From: mcarton Date: Wed, 8 Jun 2016 19:48:10 +0000 (+0200) Subject: Automatically defines the `clippy` feature X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=d7ba66bf44f993e64114e17cc15f1b0d56ae8f70;p=rust.git Automatically defines the `clippy` feature --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ff32fe13f..4009246507c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.76 — TBD +* `cargo clippy` now automatically defines the `clippy` feature + ## 0.0.75 — 2016-06-08 * Rustup to *rustc 1.11.0-nightly (763f9234b 2016-06-06)* diff --git a/README.md b/README.md index 8f699d2f741..2e40f6ed74c 100644 --- a/README.md +++ b/README.md @@ -245,22 +245,6 @@ similar crates. SYSROOT=/path/to/rustc/sysroot cargo install clippy ``` -### Configuring clippy - -You can add options to `allow`/`warn`/`deny`: - -* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`) - -* 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. - -* only some lints (`#![deny(single_match, box_vec)]`, etc) - -* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc - -Note: `deny` produces errors instead of warnings - ### Running clippy from the command line without installing 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: To deactivate the “for further information visit *wiki-link*” message you can define the `CLIPPY_DISABLE_WIKI_LINKS` environment variable. +### Allowing/denying lints + +You can add options to `allow`/`warn`/`deny`: + +* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy)]`) + +* 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. + +* only some lints (`#![deny(single_match, box_vec)]`, etc) + +* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc + +Note: `deny` produces errors instead of warnings. + +For convenience, `cargo clippy` automatically defines a `clippy` features. This +lets you set lints level and compile with or without clippy transparently: + +```rust +#[cfg_attr(feature = "clippy", allow(needless_lifetimes))] +``` + ## Link with clippy service `clippy-service` is a rust web initiative providing `rust-clippy` as a web service. diff --git a/src/main.rs b/src/main.rs index a42610e1732..43483e76a0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,11 +141,14 @@ pub fn main() { } } } else { - let args: Vec = if env::args().any(|s| s == "--sysroot") { + let mut args: Vec = if env::args().any(|s| s == "--sysroot") { env::args().collect() } else { env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect() }; + + args.extend_from_slice(&["--cfg".to_owned(), r#"feature="clippy""#.to_owned()]); + let (result, _) = rustc_driver::run_compiler(&args, &mut ClippyCompilerCalls::new()); if let Err(err_count) = result { @@ -174,6 +177,8 @@ fn process(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="clippy""#.to_owned()); let path = std::env::current_exe().expect("current executable path invalid"); let exit_status = std::process::Command::new("cargo")