2 #![feature(box_syntax)]
3 #![feature(rustc_private)]
4 #![allow(unknown_lints, missing_docs_in_private_items)]
6 const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
9 cargo clippy [options] [--] [<opts>...]
12 -h, --help Print this message
13 -V, --version Print version info and exit
15 Other options are the same as `cargo check`.
17 To allow or deny a lint from the command line you can use `cargo clippy --`
20 -W --warn OPT Set lint warnings
21 -A --allow OPT Set lint allowed
22 -D --deny OPT Set lint denied
23 -F --forbid OPT Set lint forbidden
25 The feature `cargo-clippy` is automatically defined for convenience. You can use
26 it to allow or deny lints from the code, eg.:
28 #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
31 #[allow(print_stdout)]
33 println!("{}", CARGO_CLIPPY_HELP);
36 #[allow(print_stdout)]
38 println!(env!("CARGO_PKG_VERSION"));
42 // Check for version and help flags even when invoked as 'cargo-clippy'
43 if std::env::args().any(|a| a == "--help" || a == "-h") {
47 if std::env::args().any(|a| a == "--version" || a == "-V") {
52 if let Err(code) = process(std::env::args().skip(2)) {
53 std::process::exit(code);
57 fn process<I>(mut old_args: I) -> Result<(), i32>
59 I: Iterator<Item = String>,
61 let mut args = vec!["check".to_owned()];
63 let mut found_dashes = false;
64 for arg in old_args.by_ref() {
65 found_dashes |= arg == "--";
72 let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
74 let mut path = std::env::current_exe()
75 .expect("current executable path invalid")
76 .with_file_name("clippy-driver");
78 path.set_extension("exe");
81 let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
83 std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
85 let mut fallback = std::ffi::OsString::new();
86 fallback.push("clippy_dogfood");
90 std::path::PathBuf::from(d)
97 .map(|p| ("CARGO_TARGET_DIR", p));
99 let exit_status = std::process::Command::new("cargo")
101 .env("RUSTC_WRAPPER", path)
102 .env("CLIPPY_ARGS", clippy_args)
105 .expect("could not run cargo")
107 .expect("failed to wait for cargo?");
109 if exit_status.success() {
112 Err(exit_status.code().unwrap_or(-1))