2 #![feature(box_syntax)]
3 #![feature(rustc_private)]
4 #![feature(tool_lints)]
5 #![allow(unknown_lints, clippy::missing_docs_in_private_items)]
7 use rustc_tools_util::*;
9 const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
12 cargo clippy [options] [--] [<opts>...]
15 -h, --help Print this message
16 -V, --version Print version info and exit
18 Other options are the same as `cargo check`.
20 To allow or deny a lint from the command line you can use `cargo clippy --`
23 -W --warn OPT Set lint warnings
24 -A --allow OPT Set lint allowed
25 -D --deny OPT Set lint denied
26 -F --forbid OPT Set lint forbidden
28 The feature `cargo-clippy` is automatically defined for convenience. You can use
29 it to allow or deny lints from the code, eg.:
31 #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
34 #[allow(clippy::print_stdout)]
36 println!("{}", CARGO_CLIPPY_HELP);
39 #[allow(clippy::print_stdout)]
41 let version_info = rustc_tools_util::get_version_info!();
42 println!("{}", version_info);
46 // Check for version and help flags even when invoked as 'cargo-clippy'
47 if std::env::args().any(|a| a == "--help" || a == "-h") {
52 if std::env::args().any(|a| a == "--version" || a == "-V") {
57 if let Err(code) = process(std::env::args().skip(2)) {
58 std::process::exit(code);
62 fn process<I>(mut old_args: I) -> Result<(), i32>
64 I: Iterator<Item = String>,
66 let mut args = vec!["check".to_owned()];
68 let mut found_dashes = false;
69 for arg in old_args.by_ref() {
70 found_dashes |= arg == "--";
77 let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
79 let mut path = std::env::current_exe()
80 .expect("current executable path invalid")
81 .with_file_name("clippy-driver");
83 path.set_extension("exe");
86 let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
88 std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
90 let mut fallback = std::ffi::OsString::new();
91 fallback.push("clippy_dogfood");
95 std::path::PathBuf::from(d)
101 }).map(|p| ("CARGO_TARGET_DIR", p));
103 let exit_status = std::process::Command::new("cargo")
105 .env("RUSTC_WRAPPER", path)
106 .env("CLIPPY_ARGS", clippy_args)
109 .expect("could not run cargo")
111 .expect("failed to wait for cargo?");
113 if exit_status.success() {
116 Err(exit_status.code().unwrap_or(-1))