]> git.lizzy.rs Git - rust.git/commitdiff
Automatically defines the `clippy` feature
authormcarton <cartonmartin+git@gmail.com>
Wed, 8 Jun 2016 19:48:10 +0000 (21:48 +0200)
committermcarton <cartonmartin+git@gmail.com>
Wed, 8 Jun 2016 19:53:58 +0000 (21:53 +0200)
CHANGELOG.md
README.md
src/main.rs

index 42ff32fe13ff394df6ae802262df06c34f8db5e9..4009246507c261cfd02dba424a5eb6a46f21160e 100644 (file)
@@ -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)*
 
index 8f699d2f74174b715e29551fc7f779206f6602b1..2e40f6ed74c5642617d757f4e0a535476fcb5bbb 100644 (file)
--- 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.
index a42610e17328546864cd76f33357c904335acaf4..43483e76a0fda28f000f4c87ea27fe050fe18590 100644 (file)
@@ -141,11 +141,14 @@ pub fn main() {
             }
         }
     } else {
-        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()
         };
+
+        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<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="clippy""#.to_owned());
 
     let path = std::env::current_exe().expect("current executable path invalid");
     let exit_status = std::process::Command::new("cargo")