Add a migrating message for cargo fix --edition.

This helps indicate which edition you are moving from and to.
This commit is contained in:
Eric Huss 2021-02-17 21:36:28 -08:00
parent 820537c706
commit 3f2f7e30ff
4 changed files with 44 additions and 24 deletions

View File

@ -1535,6 +1535,7 @@ fn substitute_macros(input: &str) -> String {
("[LOGOUT]", " Logout"), ("[LOGOUT]", " Logout"),
("[YANK]", " Yank"), ("[YANK]", " Yank"),
("[OWNER]", " Owner"), ("[OWNER]", " Owner"),
("[MIGRATING]", " Migrating"),
]; ];
let mut result = input.to_owned(); let mut result = input.to_owned();
for &(pat, subst) in &macros { for &(pat, subst) in &macros {

View File

@ -301,7 +301,7 @@ fn rustfix_crate(
filename: &Path, filename: &Path,
args: &FixArgs, args: &FixArgs,
) -> Result<FixedCrate, Error> { ) -> Result<FixedCrate, Error> {
args.verify_not_preparing_for_enabled_edition()?; args.check_edition_and_send_status()?;
// First up, we want to make sure that each crate is only checked by one // First up, we want to make sure that each crate is only checked by one
// process at a time. If two invocations concurrently check a crate then // process at a time. If two invocations concurrently check a crate then
@ -685,15 +685,10 @@ impl FixArgs {
} }
} }
/// Verifies that we're not both preparing for an enabled edition and enabling /// Validates the edition, and sends a message indicating what is being
/// the edition. /// done.
/// fn check_edition_and_send_status(&self) -> CargoResult<()> {
/// This indicates that `cargo fix --prepare-for` is being executed out of let to_edition = match self.prepare_for_edition {
/// order with enabling the edition itself, meaning that we wouldn't
/// actually be able to fix anything! If it looks like this is happening
/// then yield an error to the user, indicating that this is happening.
fn verify_not_preparing_for_enabled_edition(&self) -> CargoResult<()> {
let edition = match self.prepare_for_edition {
Some(s) => s, Some(s) => s,
None => { None => {
return Message::Fixing { return Message::Fixing {
@ -702,20 +697,21 @@ impl FixArgs {
.post(); .post();
} }
}; };
let enabled = match self.enabled_edition { let from_edition = self.enabled_edition.unwrap_or(Edition::Edition2015);
Some(s) => s, if from_edition == to_edition {
None => return Ok(()),
};
if edition != enabled {
return Ok(());
}
Message::EditionAlreadyEnabled { Message::EditionAlreadyEnabled {
file: self.file.display().to_string(), file: self.file.display().to_string(),
edition, edition: to_edition,
} }
.post()?; .post()?;
process::exit(1); process::exit(1);
} else {
Message::Migrating {
file: self.file.display().to_string(),
from_edition,
to_edition,
}
.post()
}
} }
} }

View File

@ -31,6 +31,11 @@ const PLEASE_REPORT_THIS_BUG: &str =
#[derive(Deserialize, Serialize, Hash, Eq, PartialEq, Clone)] #[derive(Deserialize, Serialize, Hash, Eq, PartialEq, Clone)]
pub enum Message { pub enum Message {
Migrating {
file: String,
from_edition: Edition,
to_edition: Edition,
},
Fixing { Fixing {
file: String, file: String,
}, },
@ -92,6 +97,19 @@ impl<'a> DiagnosticPrinter<'a> {
pub fn print(&mut self, msg: &Message) -> CargoResult<()> { pub fn print(&mut self, msg: &Message) -> CargoResult<()> {
match msg { match msg {
Message::Migrating {
file,
from_edition,
to_edition,
} => {
if !self.dedupe.insert(msg.clone()) {
return Ok(());
}
self.config.shell().status(
"Migrating",
&format!("{} from {} edition to {}", file, from_edition, to_edition),
)
}
Message::Fixing { file } => self Message::Fixing { file } => self
.config .config
.shell() .shell()

View File

@ -286,6 +286,7 @@ fn prepare_for_2018() {
let stderr = "\ let stderr = "\
[CHECKING] foo v0.0.1 ([..]) [CHECKING] foo v0.0.1 ([..])
[MIGRATING] src/lib.rs from 2015 edition to 2018
[FIXED] src/lib.rs (2 fixes) [FIXED] src/lib.rs (2 fixes)
[FINISHED] [..] [FINISHED] [..]
"; ";
@ -324,6 +325,7 @@ fn local_paths() {
.with_stderr( .with_stderr(
"\ "\
[CHECKING] foo v0.0.1 ([..]) [CHECKING] foo v0.0.1 ([..])
[MIGRATING] src/lib.rs from 2015 edition to 2018
[FIXED] src/lib.rs (1 fix) [FIXED] src/lib.rs (1 fix)
[FINISHED] [..] [FINISHED] [..]
", ",
@ -409,6 +411,7 @@ fn specify_rustflags() {
.with_stderr( .with_stderr(
"\ "\
[CHECKING] foo v0.0.1 ([..]) [CHECKING] foo v0.0.1 ([..])
[MIGRATING] src/lib.rs from 2015 edition to 2018
[FIXED] src/lib.rs (1 fix) [FIXED] src/lib.rs (1 fix)
[FINISHED] [..] [FINISHED] [..]
", ",
@ -842,6 +845,7 @@ fn fix_overlapping() {
.with_stderr( .with_stderr(
"\ "\
[CHECKING] foo [..] [CHECKING] foo [..]
[MIGRATING] src/lib.rs from 2015 edition to 2018
[FIXED] src/lib.rs (2 fixes) [FIXED] src/lib.rs (2 fixes)
[FINISHED] dev [..] [FINISHED] dev [..]
", ",
@ -1164,6 +1168,7 @@ fn only_warn_for_relevant_crates() {
"\ "\
[CHECKING] a v0.1.0 ([..]) [CHECKING] a v0.1.0 ([..])
[CHECKING] foo v0.1.0 ([..]) [CHECKING] foo v0.1.0 ([..])
[MIGRATING] src/lib.rs from 2015 edition to 2018
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", ",
) )