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 for arg in old_args.by_ref() {
71 let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
73 let mut path = std::env::current_exe()
74 .expect("current executable path invalid")
75 .with_file_name("clippy-driver");
77 path.set_extension("exe");
80 let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
82 std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
83 || std::ffi::OsString::from("clippy_dogfood"),
85 std::path::PathBuf::from(d)
92 .map(|p| ("CARGO_TARGET_DIR", p));
94 // Run the dogfood tests directly on nightly cargo. This is required due
95 // to a bug in rustup.rs when running cargo on custom toolchains. See issue #3118.
96 if std::env::var_os("CLIPPY_DOGFOOD").is_some() && cfg!(windows) {
97 args.insert(0, "+nightly".to_string());
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))