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

Updates to edition handling. #9184

Merged
merged 11 commits into from
Feb 23, 2021
Prev Previous commit
Next Next commit
Add a migrating message for cargo fix --edition.
This helps indicate which edition you are moving from and to.
ehuss committed Feb 18, 2021
commit 3f2f7e30ff7aa2045010ac845d96f652f118ff3e
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1535,6 +1535,7 @@ fn substitute_macros(input: &str) -> String {
("[LOGOUT]", " Logout"),
("[YANK]", " Yank"),
("[OWNER]", " Owner"),
("[MIGRATING]", " Migrating"),
];
let mut result = input.to_owned();
for &(pat, subst) in &macros {
44 changes: 20 additions & 24 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
@@ -301,7 +301,7 @@ fn rustfix_crate(
filename: &Path,
args: &FixArgs,
) -> 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
// 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
/// the edition.
///
/// This indicates that `cargo fix --prepare-for` is being executed out of
/// 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 {
/// Validates the edition, and sends a message indicating what is being
/// done.
fn check_edition_and_send_status(&self) -> CargoResult<()> {
let to_edition = match self.prepare_for_edition {
Some(s) => s,
None => {
return Message::Fixing {
@@ -702,20 +697,21 @@ impl FixArgs {
.post();
}
};
let enabled = match self.enabled_edition {
Some(s) => s,
None => return Ok(()),
};
if edition != enabled {
return Ok(());
}

Message::EditionAlreadyEnabled {
file: self.file.display().to_string(),
edition,
let from_edition = self.enabled_edition.unwrap_or(Edition::Edition2015);
if from_edition == to_edition {
Message::EditionAlreadyEnabled {
file: self.file.display().to_string(),
edition: to_edition,
}
.post()?;
process::exit(1);
} else {
Message::Migrating {
file: self.file.display().to_string(),
from_edition,
to_edition,
}
.post()
}
.post()?;

process::exit(1);
}
}
18 changes: 18 additions & 0 deletions src/cargo/util/diagnostic_server.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,11 @@ const PLEASE_REPORT_THIS_BUG: &str =

#[derive(Deserialize, Serialize, Hash, Eq, PartialEq, Clone)]
pub enum Message {
Migrating {
file: String,
from_edition: Edition,
to_edition: Edition,
},
Fixing {
file: String,
},
@@ -92,6 +97,19 @@ impl<'a> DiagnosticPrinter<'a> {

pub fn print(&mut self, msg: &Message) -> CargoResult<()> {
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
.config
.shell()
5 changes: 5 additions & 0 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
@@ -286,6 +286,7 @@ fn prepare_for_2018() {

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