diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 275a471bd17..e571bf1edd9 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -309,7 +309,12 @@ 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(); + 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"); 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() {