Skip to content

Commit f0075c5

Browse files
committed
Auto merge of #7162 - yaahallo:clippyargs, r=ehuss
reimplement arg passthrough for clippy-driver Prior to this change, the old cargo subcommand version of `cargo clippy` had a feature to pass trailing args down to clippy-driver but when this the subcommand was reimplemented inside of cargo this feature was left out accidentally. This change readds the feature to to capture all args after a trailing -- and forward them down to clippy-driver via an env variable.
2 parents 2322917 + 42a00c1 commit f0075c5

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/bin/cargo/commands/clippy.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cargo::util;
66
pub fn cli() -> App {
77
subcommand("clippy-preview")
88
.about("Checks a package to catch common mistakes and improve your Rust code.")
9+
.arg(Arg::with_name("args").multiple(true))
910
.arg_package_spec(
1011
"Package(s) to check",
1112
"Check all packages in the workspace",
@@ -69,7 +70,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6970
.into());
7071
}
7172

72-
let wrapper = util::process(util::config::clippy_driver());
73+
let mut wrapper = util::process(util::config::clippy_driver());
74+
75+
if let Some(clippy_args) = args.values_of("args") {
76+
wrapper.args(&clippy_args.collect::<Vec<_>>());
77+
}
78+
7379
compile_opts.build_config.primary_unit_rustc = Some(wrapper);
7480
compile_opts.build_config.force_rebuild = true;
7581

src/cargo/core/compiler/compilation.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ impl<'cfg> Compilation<'cfg> {
7979
pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> CargoResult<Compilation<'cfg>> {
8080
let mut rustc = bcx.rustc.process();
8181

82-
let mut primary_unit_rustc_process =
83-
bcx.build_config.primary_unit_rustc.clone().map(|mut r| {
84-
r.arg(&bcx.rustc.path);
85-
r
86-
});
82+
let mut primary_unit_rustc_process = bcx.build_config.primary_unit_rustc.clone();
8783

8884
if bcx.config.extra_verbose() {
8985
rustc.display_env_vars();

src/cargo/ops/fix.rs

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
130130
server.configure(&mut wrapper);
131131
}
132132

133+
let rustc = opts.compile_opts.config.load_global_rustc(Some(ws))?;
134+
wrapper.arg(&rustc.path);
135+
133136
// primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
134137
// repeating build until there are no more changes to be applied
135138
opts.compile_opts.build_config.primary_unit_rustc = Some(wrapper);

tests/testsuite/clippy.rs

+34
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,37 @@ fn clippy_force_rebuild() {
3838
.with_stderr_contains("[..]assert!(true)[..]")
3939
.run();
4040
}
41+
42+
#[cargo_test]
43+
fn clippy_passes_args() {
44+
if !clippy_is_available() {
45+
return;
46+
}
47+
48+
// This is just a random clippy lint (assertions_on_constants) that
49+
// hopefully won't change much in the future.
50+
let p = project()
51+
.file(
52+
"Cargo.toml",
53+
r#"
54+
[package]
55+
name = "foo"
56+
version = "0.1.0"
57+
58+
[dependencies]
59+
"#,
60+
)
61+
.file("src/lib.rs", "pub fn f() { assert!(true); }")
62+
.build();
63+
64+
p.cargo("clippy-preview -Zunstable-options -v -- -Aclippy::assertions_on_constants")
65+
.masquerade_as_nightly_cargo()
66+
.with_stderr_does_not_contain("[..]assert!(true)[..]")
67+
.run();
68+
69+
// Make sure it runs again.
70+
p.cargo("clippy-preview -Zunstable-options -v")
71+
.masquerade_as_nightly_cargo()
72+
.with_stderr_contains("[..]assert!(true)[..]")
73+
.run();
74+
}

0 commit comments

Comments
 (0)