2 #![feature(box_syntax)]
3 #![feature(rustc_private)]
4 #![allow(clippy::missing_docs_in_private_items)]
6 use rustc_tools_util::*;
8 const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
11 cargo clippy [options] [--] [<opts>...]
14 -h, --help Print this message
15 -V, --version Print version info and exit
17 Other options are the same as `cargo check`.
19 To allow or deny a lint from the command line you can use `cargo clippy --`
22 -W --warn OPT Set lint warnings
23 -A --allow OPT Set lint allowed
24 -D --deny OPT Set lint denied
25 -F --forbid OPT Set lint forbidden
27 You can use tool lints to allow or deny lints from your code, eg.:
29 #[allow(clippy::needless_lifetimes)]
33 println!("{}", CARGO_CLIPPY_HELP);
37 let version_info = rustc_tools_util::get_version_info!();
38 println!("{}", version_info);
42 // Check for version and help flags even when invoked as 'cargo-clippy'
43 if std::env::args().any(|a| a == "--help" || a == "-h") {
48 if std::env::args().any(|a| a == "--version" || a == "-V") {
53 if let Err(code) = process(std::env::args().skip(2)) {
54 std::process::exit(code);
58 fn process<I>(mut old_args: I) -> Result<(), i32>
60 I: Iterator<Item = String>,
62 let mut args = vec!["check".to_owned()];
64 let mut found_dashes = false;
65 for arg in old_args.by_ref() {
66 found_dashes |= arg == "--";
73 let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
75 let mut path = std::env::current_exe()
76 .expect("current executable path invalid")
77 .with_file_name("clippy-driver");
79 path.set_extension("exe");
82 let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
84 std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
86 let mut fallback = std::ffi::OsString::new();
87 fallback.push("clippy_dogfood");
91 std::path::PathBuf::from(d)
98 .map(|p| ("CARGO_TARGET_DIR", p));
100 let exit_status = std::process::Command::new("cargo")
102 .env("RUSTC_WRAPPER", path)
103 .env("CLIPPY_ARGS", clippy_args)
106 .expect("could not run cargo")
108 .expect("failed to wait for cargo?");
110 if exit_status.success() {
113 Err(exit_status.code().unwrap_or(-1))