From 8344e9b013ab561495c1773e6f4613ddb1120faa Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 29 Aug 2018 16:44:18 +0200 Subject: [PATCH 1/2] Cargo fix --prepare-for should only apply edition fixes --- src/cargo/ops/fix.rs | 4 +++- tests/testsuite/fix.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 275a471bd17..d5bfcdbcfc3 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -309,7 +309,9 @@ fn rustfix_and_fix(fixes: &mut FixedCrate, rustc: &Path, filename: &Path, args: // If not empty, filter by these lints // // TODO: Implement a way to specify this - let only = HashSet::new(); + let mut only = HashSet::new(); + only.insert("rust_2018_compatibility".to_string()); + only.insert("rust_2015_compatibility".to_string()); let mut cmd = Command::new(rustc); cmd.arg("--error-format=json"); diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 0a5f9f2a06f..0de547450f1 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -880,6 +880,20 @@ fn fix_overlapping() { assert!(contents.contains("crate::foo::()")); } +#[test] +fn prepare_for_leaves_unrelated_warnings_alone() { + if !is_nightly() { return; } + + let p = project().file("src/main.rs", "fn main() { let x = 1; }").build(); + + p.cargo("fix --allow-no-vcs --prepare-for 2018").run(); + + let contents = p.read_file("src/main.rs"); + println!("{}", contents); + assert!(contents.contains("let x = 1;")); + assert!(!contents.contains("let _x = 1;")); +} + #[test] fn fix_idioms() { if !is_nightly() { From 5cc1d9b6a5327db37902cd506873e83634e22876 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 29 Aug 2018 17:40:14 +0200 Subject: [PATCH 2/2] Define the only warnings to fix from prepare_for_edition --- src/cargo/ops/fix.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index d5bfcdbcfc3..e571bf1edd9 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -310,8 +310,11 @@ fn rustfix_and_fix(fixes: &mut FixedCrate, rustc: &Path, filename: &Path, args: // // TODO: Implement a way to specify this let mut only = HashSet::new(); - only.insert("rust_2018_compatibility".to_string()); - only.insert("rust_2015_compatibility".to_string()); + match &args.prepare_for_edition { + PrepareFor::Edition(edition) => { only.insert(format!("rust_{}_compatibility", edition)); }, + PrepareFor::Next => { only.insert(format!("rust_{}_compatibility", args.next_edition())); }, + PrepareFor::None => (), + } let mut cmd = Command::new(rustc); cmd.arg("--error-format=json");