From be0cbb57c760d4ac265fbc4217fa97e4c81cf153 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 15 Jul 2021 07:12:34 -0700 Subject: [PATCH] `cargo fix --edition`: extend warning when on latest edition --- src/cargo/util/diagnostic_server.rs | 31 ++++++++++++++++++++++++++--- tests/testsuite/fix.rs | 6 ++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/cargo/util/diagnostic_server.rs b/src/cargo/util/diagnostic_server.rs index cd1ae0c41ef..e2e8dad46cc 100644 --- a/src/cargo/util/diagnostic_server.rs +++ b/src/cargo/util/diagnostic_server.rs @@ -181,10 +181,35 @@ impl<'a> DiagnosticPrinter<'a> { if !self.dedupe.insert(msg.clone()) { return Ok(()); } - self.config.shell().warn(&format!( - "`{}` is already on the latest edition ({}), unable to migrate further", + let warning = format!( + "`{}` is already on the latest edition ({}), \ + unable to migrate further", file, edition - )) + ); + // Don't give a really verbose warning if it has already been issued. + if self.dedupe.insert(Message::EditionAlreadyEnabled { + file: "".to_string(), // Dummy, so that this only long-warns once. + edition: *edition, + }) { + self.config.shell().warn(&format!("\ +{} + +If you are trying to migrate from the previous edition ({prev_edition}), the +process requires following these steps: + +1. Start with `edition = \"{prev_edition}\"` in `Cargo.toml` +2. Run `cargo fix --edition` +3. Modify `Cargo.toml` to set `edition = \"{this_edition}\"` +4. Run `cargo build` or `cargo test` to verify the fixes worked + +More details may be found at +https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html +", + warning, this_edition=edition, prev_edition=edition.previous().unwrap() + )) + } else { + self.config.shell().warn(warning) + } } } } diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index f9aac34b5d5..c797766af31 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -925,11 +925,10 @@ fn prepare_for_already_on_latest_unstable() { p.cargo("fix --edition --allow-no-vcs") .masquerade_as_nightly_cargo() + .with_stderr_contains("[CHECKING] foo [..]") .with_stderr_contains(&format!( "\ -[CHECKING] foo [..] [WARNING] `src/lib.rs` is already on the latest edition ({next_edition}), unable to migrate further -[FINISHED] [..] ", next_edition = next_edition )) @@ -961,11 +960,10 @@ fn prepare_for_already_on_latest_stable() { .build(); p.cargo("fix --edition --allow-no-vcs") + .with_stderr_contains("[CHECKING] foo [..]") .with_stderr_contains(&format!( "\ -[CHECKING] foo [..] [WARNING] `src/lib.rs` is already on the latest edition ({latest_stable}), unable to migrate further -[FINISHED] [..] ", latest_stable = latest_stable ))