|
1 | 1 | // error-pattern:yummy
|
2 | 2 | #![feature(box_syntax)]
|
3 | 3 | #![feature(rustc_private)]
|
| 4 | +#![feature(static_in_const)] |
4 | 5 |
|
5 | 6 | #![allow(unknown_lints, missing_docs_in_private_items)]
|
6 | 7 |
|
@@ -110,6 +111,36 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
|
110 | 111 |
|
111 | 112 | use std::path::Path;
|
112 | 113 |
|
| 114 | +const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code. |
| 115 | +
|
| 116 | +Usage: |
| 117 | + cargo clippy [options] [--] [<opts>...] |
| 118 | +
|
| 119 | +Common options: |
| 120 | + -h, --help Print this message |
| 121 | + --features Features to compile for the package |
| 122 | +
|
| 123 | +Other options are the same as `cargo rustc`. |
| 124 | +
|
| 125 | +To allow or deny a lint from the command line you can use `cargo clippy --` |
| 126 | +with: |
| 127 | +
|
| 128 | + -W --warn OPT Set lint warnings |
| 129 | + -A --allow OPT Set lint allowed |
| 130 | + -D --deny OPT Set lint denied |
| 131 | + -F --forbid OPT Set lint forbidden |
| 132 | +
|
| 133 | +The feature `cargo-clippy` is automatically defined for convenience. You can use |
| 134 | +it to allow or deny lints from the code, eg.: |
| 135 | +
|
| 136 | + #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))] |
| 137 | +"#; |
| 138 | + |
| 139 | +#[allow(print_stdout)] |
| 140 | +fn show_help() { |
| 141 | + println!("{}", CARGO_CLIPPY_HELP); |
| 142 | +} |
| 143 | + |
113 | 144 | pub fn main() {
|
114 | 145 | use std::env;
|
115 | 146 |
|
@@ -138,9 +169,16 @@ pub fn main() {
|
138 | 169 |
|
139 | 170 | if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
140 | 171 | // this arm is executed on the initial call to `cargo clippy`
|
| 172 | + |
| 173 | + if std::env::args().any(|a| a == "--help" || a == "-h") { |
| 174 | + show_help(); |
| 175 | + return; |
| 176 | + } |
| 177 | + |
141 | 178 | let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));
|
142 | 179 |
|
143 | 180 | let mut metadata = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)).expect("could not obtain cargo metadata");
|
| 181 | + |
144 | 182 | assert_eq!(metadata.version, 1);
|
145 | 183 |
|
146 | 184 | let manifest_path = manifest_path_arg.map(|arg| PathBuf::from(Path::new(&arg["--manifest-path=".len()..])));
|
@@ -181,13 +219,16 @@ pub fn main() {
|
181 | 219 |
|
182 | 220 | // this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
|
183 | 221 | // without having to pass --sysroot or anything
|
184 |
| - let args: Vec<String> = if env::args().any(|s| s == "--sysroot") { |
| 222 | + let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") { |
185 | 223 | env::args().collect()
|
186 | 224 | } else {
|
187 | 225 | env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
|
188 | 226 | };
|
| 227 | + |
189 | 228 | // this check ensures that dependencies are built but not linted and the final crate is
|
190 | 229 | // linted but not built
|
| 230 | + args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); |
| 231 | + |
191 | 232 | let mut ccc = ClippyCompilerCalls::new(env::args().any(|s| s == "-Zno-trans"));
|
192 | 233 | let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None);
|
193 | 234 |
|
@@ -219,6 +260,8 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
|
219 | 260 | args.push(String::from("--sysroot"));
|
220 | 261 | args.push(sysroot.to_owned());
|
221 | 262 | args.push("-Zno-trans".to_owned());
|
| 263 | + args.push("--cfg".to_owned()); |
| 264 | + args.push(r#"feature="cargo-clippy""#.to_owned()); |
222 | 265 |
|
223 | 266 | let path = std::env::current_exe().expect("current executable path invalid");
|
224 | 267 | let exit_status = std::process::Command::new("cargo")
|
|
0 commit comments