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 mut extra_envs = vec![];
82 if std::env::var("CLIPPY_DOGFOOD").is_ok() {
83 let target_dir = std::env::var("CARGO_MANIFEST_DIR")
85 std::path::PathBuf::from(m)
91 .unwrap_or_else(|_| "clippy_dogfood".to_string());
93 extra_envs.push(("CARGO_TARGET_DIR", target_dir));
96 let exit_status = std::process::Command::new("cargo")
98 .env("RUSTC_WRAPPER", path)
99 .env("CLIPPY_ARGS", clippy_args)
102 .expect("could not run cargo")
104 .expect("failed to wait for cargo?");
106 if exit_status.success() {
109 Err(exit_status.code().unwrap_or(-1))