Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reimplement arg passthrough for clippy-driver #7162

Merged
merged 4 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -78,11 +78,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();
}