1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 // error-pattern:yummy
11 #![feature(box_syntax)]
12 #![feature(rustc_private)]
13 #![allow(clippy::missing_docs_in_private_items)]
15 use rustc_tools_util::*;
17 const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
20 cargo clippy [options] [--] [<opts>...]
23 -h, --help Print this message
24 -V, --version Print version info and exit
26 Other options are the same as `cargo check`.
28 To allow or deny a lint from the command line you can use `cargo clippy --`
31 -W --warn OPT Set lint warnings
32 -A --allow OPT Set lint allowed
33 -D --deny OPT Set lint denied
34 -F --forbid OPT Set lint forbidden
36 You can use tool lints to allow or deny lints from your code, eg.:
38 #[allow(clippy::needless_lifetimes)]
42 println!("{}", CARGO_CLIPPY_HELP);
46 let version_info = rustc_tools_util::get_version_info!();
47 println!("{}", version_info);
51 // Check for version and help flags even when invoked as 'cargo-clippy'
52 if std::env::args().any(|a| a == "--help" || a == "-h") {
57 if std::env::args().any(|a| a == "--version" || a == "-V") {
62 if let Err(code) = process(std::env::args().skip(2)) {
63 std::process::exit(code);
67 fn process<I>(mut old_args: I) -> Result<(), i32>
69 I: Iterator<Item = String>,
71 let mut args = vec!["check".to_owned()];
73 let mut found_dashes = false;
74 for arg in old_args.by_ref() {
75 found_dashes |= arg == "--";
82 let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
84 let mut path = std::env::current_exe()
85 .expect("current executable path invalid")
86 .with_file_name("clippy-driver");
88 path.set_extension("exe");
91 let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
93 std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
95 let mut fallback = std::ffi::OsString::new();
96 fallback.push("clippy_dogfood");
100 std::path::PathBuf::from(d)
107 .map(|p| ("CARGO_TARGET_DIR", p));
109 let exit_status = std::process::Command::new("cargo")
111 .env("RUSTC_WRAPPER", path)
112 .env("CLIPPY_ARGS", clippy_args)
115 .expect("could not run cargo")
117 .expect("failed to wait for cargo?");
119 if exit_status.success() {
122 Err(exit_status.code().unwrap_or(-1))