Skip to content

Commit be0cbb5

Browse files
committed
cargo fix --edition: extend warning when on latest edition
1 parent 66a6737 commit be0cbb5

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/cargo/util/diagnostic_server.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,35 @@ impl<'a> DiagnosticPrinter<'a> {
181181
if !self.dedupe.insert(msg.clone()) {
182182
return Ok(());
183183
}
184-
self.config.shell().warn(&format!(
185-
"`{}` is already on the latest edition ({}), unable to migrate further",
184+
let warning = format!(
185+
"`{}` is already on the latest edition ({}), \
186+
unable to migrate further",
186187
file, edition
187-
))
188+
);
189+
// Don't give a really verbose warning if it has already been issued.
190+
if self.dedupe.insert(Message::EditionAlreadyEnabled {
191+
file: "".to_string(), // Dummy, so that this only long-warns once.
192+
edition: *edition,
193+
}) {
194+
self.config.shell().warn(&format!("\
195+
{}
196+
197+
If you are trying to migrate from the previous edition ({prev_edition}), the
198+
process requires following these steps:
199+
200+
1. Start with `edition = \"{prev_edition}\"` in `Cargo.toml`
201+
2. Run `cargo fix --edition`
202+
3. Modify `Cargo.toml` to set `edition = \"{this_edition}\"`
203+
4. Run `cargo build` or `cargo test` to verify the fixes worked
204+
205+
More details may be found at
206+
https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html
207+
",
208+
warning, this_edition=edition, prev_edition=edition.previous().unwrap()
209+
))
210+
} else {
211+
self.config.shell().warn(warning)
212+
}
188213
}
189214
}
190215
}

tests/testsuite/fix.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -925,11 +925,10 @@ fn prepare_for_already_on_latest_unstable() {
925925

926926
p.cargo("fix --edition --allow-no-vcs")
927927
.masquerade_as_nightly_cargo()
928+
.with_stderr_contains("[CHECKING] foo [..]")
928929
.with_stderr_contains(&format!(
929930
"\
930-
[CHECKING] foo [..]
931931
[WARNING] `src/lib.rs` is already on the latest edition ({next_edition}), unable to migrate further
932-
[FINISHED] [..]
933932
",
934933
next_edition = next_edition
935934
))
@@ -961,11 +960,10 @@ fn prepare_for_already_on_latest_stable() {
961960
.build();
962961

963962
p.cargo("fix --edition --allow-no-vcs")
963+
.with_stderr_contains("[CHECKING] foo [..]")
964964
.with_stderr_contains(&format!(
965965
"\
966-
[CHECKING] foo [..]
967966
[WARNING] `src/lib.rs` is already on the latest edition ({latest_stable}), unable to migrate further
968-
[FINISHED] [..]
969967
",
970968
latest_stable = latest_stable
971969
))

0 commit comments

Comments
 (0)