Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fix --edition: extend warning when on latest edition #9694

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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