Skip to content

Commit 1f49100

Browse files
committed
Auto merge of #5949 - dwijnand:extract-FixArgs-prepare_for_edition_resolve, r=alexcrichton
Extract FixArgs::prepare_for_edition_resolve A little code dedup from working on #5948.
2 parents 8b2082b + 35f745a commit 1f49100

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/cargo/ops/fix.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,8 @@ impl FixArgs {
557557
if edition == "2018" { cmd.arg("-Wrust-2018-idioms"); }
558558
}
559559
}
560-
match &self.prepare_for_edition {
561-
PrepareFor::Edition(edition) => {
562-
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
563-
}
564-
PrepareFor::Next => {
565-
let edition = self.next_edition();
566-
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
567-
}
568-
PrepareFor::None => {}
560+
if let Some(edition) = self.prepare_for_edition_resolve() {
561+
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
569562
}
570563
}
571564

@@ -577,10 +570,9 @@ impl FixArgs {
577570
/// actually be able to fix anything! If it looks like this is happening
578571
/// then yield an error to the user, indicating that this is happening.
579572
fn verify_not_preparing_for_enabled_edition(&self) -> CargoResult<()> {
580-
let edition = match &self.prepare_for_edition {
581-
PrepareFor::Edition(s) => s,
582-
PrepareFor::Next => self.next_edition(),
583-
PrepareFor::None => return Ok(()),
573+
let edition = match self.prepare_for_edition_resolve() {
574+
Some(s) => s,
575+
None => return Ok(()),
584576
};
585577
let enabled = match &self.enabled_edition {
586578
Some(s) => s,
@@ -609,10 +601,9 @@ impl FixArgs {
609601
///
610602
/// If this is the case, issue a warning.
611603
fn warn_if_preparing_probably_inert(&self) -> CargoResult<()> {
612-
let edition = match &self.prepare_for_edition {
613-
PrepareFor::Edition(s) => s,
614-
PrepareFor::Next => self.next_edition(),
615-
PrepareFor::None => return Ok(()),
604+
let edition = match self.prepare_for_edition_resolve() {
605+
Some(s) => s,
606+
None => return Ok(()),
616607
};
617608
let path = match &self.file {
618609
Some(s) => s,
@@ -635,6 +626,14 @@ impl FixArgs {
635626
Ok(())
636627
}
637628

629+
fn prepare_for_edition_resolve(&self) -> Option<&str> {
630+
match &self.prepare_for_edition {
631+
PrepareFor::Edition(s) => Some(s),
632+
PrepareFor::Next => Some(self.next_edition()),
633+
PrepareFor::None => None,
634+
}
635+
}
636+
638637
fn next_edition(&self) -> &str {
639638
match self.enabled_edition.as_ref().map(|s| &**s) {
640639
// 2015 -> 2018,

0 commit comments

Comments
 (0)