diff --git a/src/bin/cargo/commands/clippy.rs b/src/bin/cargo/commands/clippy.rs index 8e838389b0f..c591acfacbc 100644 --- a/src/bin/cargo/commands/clippy.rs +++ b/src/bin/cargo/commands/clippy.rs @@ -71,6 +71,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let wrapper = util::process(util::config::clippy_driver()); compile_opts.build_config.primary_unit_rustc = Some(wrapper); + compile_opts.build_config.force_rebuild = true; ops::compile(&ws, &compile_opts)?; Ok(()) diff --git a/tests/testsuite/clippy.rs b/tests/testsuite/clippy.rs new file mode 100644 index 00000000000..8348d2816ac --- /dev/null +++ b/tests/testsuite/clippy.rs @@ -0,0 +1,40 @@ +use crate::support::{clippy_is_available, project, registry::Package}; + +#[cargo_test] +// Clippy should never be considered fresh. +fn clippy_force_rebuild() { + if !clippy_is_available() { + return; + } + + Package::new("dep1", "0.1.0").publish(); + + // 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] + dep1 = "0.1" + "#, + ) + .file("src/lib.rs", "pub fn f() { assert!(true); }") + .build(); + + p.cargo("clippy-preview -Zunstable-options -v") + .masquerade_as_nightly_cargo() + .with_stderr_contains("[..]assert!(true)[..]") + .run(); + + // Make sure it runs again. + p.cargo("clippy-preview -Zunstable-options -v") + .masquerade_as_nightly_cargo() + .with_stderr_contains("[FRESH] dep1 v0.1.0") + .with_stderr_contains("[..]assert!(true)[..]") + .run(); +} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index c1a7f06f0dd..618c92ceb23 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -29,6 +29,7 @@ mod cargo_features; mod cfg; mod check; mod clean; +mod clippy; mod collisions; mod concurrent; mod config;