@@ -111,8 +111,7 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
111
111
112
112
use std:: path:: Path ;
113
113
114
- const CARGO_CLIPPY_HELP : & str = "\
115
- Checks a package to catch common mistakes and improve your Rust code.
114
+ const CARGO_CLIPPY_HELP : & str = r#"Checks a package to catch common mistakes and improve your Rust code.
116
115
117
116
Usage:
118
117
cargo clippy [options] [--] [<opts>...]
@@ -129,8 +128,13 @@ one of:
129
128
-W --warn OPT Set lint warnings
130
129
-A --allow OPT Set lint allowed
131
130
-D --deny OPT Set lint denied
132
- -F --forbid OPT Set lint forbidden\
133
- ";
131
+ -F --forbid OPT Set lint forbidden
132
+
133
+ The feature `cargo-clippy` is automatically defined for convinence. You can use
134
+ it to allow or deny lints, eg.:
135
+
136
+ #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
137
+ "# ;
134
138
135
139
pub fn main ( ) {
136
140
use std:: env;
@@ -213,13 +217,16 @@ pub fn main() {
213
217
214
218
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
215
219
// without having to pass --sysroot or anything
216
- let args: Vec < String > = if env:: args ( ) . any ( |s| s == "--sysroot" ) {
220
+ let mut args: Vec < String > = if env:: args ( ) . any ( |s| s == "--sysroot" ) {
217
221
env:: args ( ) . collect ( )
218
222
} else {
219
223
env:: args ( ) . chain ( Some ( "--sysroot" . to_owned ( ) ) ) . chain ( Some ( sys_root) ) . collect ( )
220
224
} ;
225
+
221
226
// this check ensures that dependencies are built but not linted and the final crate is
222
227
// linted but not built
228
+ args. extend_from_slice ( & [ "--cfg" . to_owned ( ) , r#"feature="cargo-clippy""# . to_owned ( ) ] ) ;
229
+
223
230
let mut ccc = ClippyCompilerCalls :: new ( env:: args ( ) . any ( |s| s == "-Zno-trans" ) ) ;
224
231
let ( result, _) = rustc_driver:: run_compiler ( & args, & mut ccc, None , None ) ;
225
232
@@ -251,6 +258,8 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
251
258
args. push ( String :: from ( "--sysroot" ) ) ;
252
259
args. push ( sysroot. to_owned ( ) ) ;
253
260
args. push ( "-Zno-trans" . to_owned ( ) ) ;
261
+ args. push ( "--cfg" . to_owned ( ) ) ;
262
+ args. push ( r#"feature="cargo-clippy""# . to_owned ( ) ) ;
254
263
255
264
let path = std:: env:: current_exe ( ) . expect ( "current executable path invalid" ) ;
256
265
let exit_status = std:: process:: Command :: new ( "cargo" )
0 commit comments