Skip to content

Commit

Permalink
cargo fix --edition: extend warning when on latest edition
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jul 15, 2021
1 parent 66a6737 commit be0cbb5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
31 changes: 28 additions & 3 deletions src/cargo/util/diagnostic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand Down Expand Up @@ -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
))
Expand Down

0 comments on commit be0cbb5

Please sign in to comment.