mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Don't turn on edition lints for unfixed crates
Currently Cargo runs the risk of turning on the edition lints for crates which `cargo fix` isn't actually fixing, which means you'll get a huge deluge of lints that would otherwise be automatically fixable! Fix this situation by only enabling lints in the same cases that we're actually applying fixes. Closes rust-lang-nursery/rustfix#150
This commit is contained in:
parent
56d630f1eb
commit
4f784a10d1
@ -165,7 +165,7 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
|
||||
// not the best heuristic but matches what Cargo does today at least.
|
||||
let mut fixes = FixedCrate::default();
|
||||
if let Some(path) = &args.file {
|
||||
if env::var("CARGO_PRIMARY_PACKAGE").is_ok() {
|
||||
if args.primary_package {
|
||||
trace!("start rustfixing {:?}", path);
|
||||
fixes = rustfix_crate(&lock_addr, rustc.as_ref(), path, &args)?;
|
||||
}
|
||||
@ -503,6 +503,7 @@ struct FixArgs {
|
||||
idioms: bool,
|
||||
enabled_edition: Option<String>,
|
||||
other: Vec<OsString>,
|
||||
primary_package: bool,
|
||||
}
|
||||
|
||||
enum PrepareFor {
|
||||
@ -543,6 +544,7 @@ impl FixArgs {
|
||||
ret.prepare_for_edition = PrepareFor::Next;
|
||||
}
|
||||
ret.idioms = env::var(IDIOMS_ENV).is_ok();
|
||||
ret.primary_package = env::var("CARGO_PRIMARY_PACKAGE").is_ok();
|
||||
ret
|
||||
}
|
||||
|
||||
@ -554,14 +556,16 @@ impl FixArgs {
|
||||
.arg("--cap-lints=warn");
|
||||
if let Some(edition) = &self.enabled_edition {
|
||||
cmd.arg("--edition").arg(edition);
|
||||
if self.idioms {
|
||||
if self.idioms && self.primary_package {
|
||||
if edition == "2018" { cmd.arg("-Wrust-2018-idioms"); }
|
||||
}
|
||||
}
|
||||
if self.primary_package {
|
||||
if let Some(edition) = self.prepare_for_edition_resolve() {
|
||||
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify that we're not both preparing for an enabled edition and enabling
|
||||
/// the edition.
|
||||
|
@ -1072,3 +1072,47 @@ fn does_not_crash_with_rustc_wrapper() {
|
||||
.env("RUSTC_WRAPPER", "/usr/bin/env")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_warn_for_relevant_crates() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
a = { path = 'a' }
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.file(
|
||||
"a/Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "a"
|
||||
version = "0.1.0"
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"a/src/lib.rs",
|
||||
"
|
||||
pub fn foo() {}
|
||||
pub mod bar {
|
||||
use foo;
|
||||
pub fn baz() { foo() }
|
||||
}
|
||||
",
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --allow-no-vcs --edition")
|
||||
.with_stderr("\
|
||||
[CHECKING] a v0.1.0 ([..])
|
||||
[CHECKING] foo v0.1.0 ([..])
|
||||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||
")
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user