Skip to content

Commit

Permalink
Auto merge of #7162 - yaahallo:clippyargs, r=ehuss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Aug 9, 2019
2 parents 2322917 + 42a00c1 commit f0075c5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/bin/cargo/commands/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cargo::util;
pub fn cli() -> App {
subcommand("clippy-preview")
.about("Checks a package to catch common mistakes and improve your Rust code.")
.arg(Arg::with_name("args").multiple(true))
.arg_package_spec(
"Package(s) to check",
"Check all packages in the workspace",
Expand Down Expand Up @@ -69,7 +70,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
.into());
}

let wrapper = util::process(util::config::clippy_driver());
let mut wrapper = util::process(util::config::clippy_driver());

if let Some(clippy_args) = args.values_of("args") {
wrapper.args(&clippy_args.collect::<Vec<_>>());
}

compile_opts.build_config.primary_unit_rustc = Some(wrapper);
compile_opts.build_config.force_rebuild = true;

Expand Down
6 changes: 1 addition & 5 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ impl<'cfg> Compilation<'cfg> {
pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> CargoResult<Compilation<'cfg>> {
let mut rustc = bcx.rustc.process();

let mut primary_unit_rustc_process =
bcx.build_config.primary_unit_rustc.clone().map(|mut r| {
r.arg(&bcx.rustc.path);
r
});
let mut primary_unit_rustc_process = bcx.build_config.primary_unit_rustc.clone();

if bcx.config.extra_verbose() {
rustc.display_env_vars();
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
server.configure(&mut wrapper);
}

let rustc = opts.compile_opts.config.load_global_rustc(Some(ws))?;
wrapper.arg(&rustc.path);

// primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
// repeating build until there are no more changes to be applied
opts.compile_opts.build_config.primary_unit_rustc = Some(wrapper);
Expand Down
34 changes: 34 additions & 0 deletions tests/testsuite/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,37 @@ fn clippy_force_rebuild() {
.with_stderr_contains("[..]assert!(true)[..]")
.run();
}

#[cargo_test]
fn clippy_passes_args() {
if !clippy_is_available() {
return;
}

// This is just a random clippy lint (assertions_on_constants) that
// hopefully won't change much in the future.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
"#,
)
.file("src/lib.rs", "pub fn f() { assert!(true); }")
.build();

p.cargo("clippy-preview -Zunstable-options -v -- -Aclippy::assertions_on_constants")
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain("[..]assert!(true)[..]")
.run();

// Make sure it runs again.
p.cargo("clippy-preview -Zunstable-options -v")
.masquerade_as_nightly_cargo()
.with_stderr_contains("[..]assert!(true)[..]")
.run();
}

0 comments on commit f0075c5

Please sign in to comment.