Skip to content

Commit c303213

Browse files
committed
cargo fix: Remove --prepare-for option.
This was deprecated, never officially part of the stable release.
1 parent 15513ce commit c303213

4 files changed

Lines changed: 20 additions & 50 deletions

File tree

src/bin/cargo/commands/fix.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@ pub fn cli() -> App {
4141
.long("edition")
4242
.help("Fix in preparation for the next edition"),
4343
)
44-
.arg(
45-
// This is a deprecated argument, we'll want to phase it out
46-
// eventually.
47-
Arg::with_name("prepare-for")
48-
.long("prepare-for")
49-
.help("Fix warnings in preparation of an edition upgrade")
50-
.takes_value(true)
51-
.possible_values(&["2018"])
52-
.conflicts_with("edition")
53-
.hidden(true),
54-
)
5544
.arg(
5645
Arg::with_name("idioms")
5746
.long("edition-idioms")
@@ -111,7 +100,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
111100
&ws,
112101
&mut ops::FixOptions {
113102
edition: args.is_present("edition"),
114-
prepare_for: args.value_of("prepare-for"),
115103
idioms: args.is_present("idioms"),
116104
compile_opts: opts,
117105
allow_dirty: args.is_present("allow-dirty"),

src/cargo/core/features.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ impl Edition {
182182
}
183183
}
184184

185+
/// Returns the next edition from this edition, returning the last edition
186+
/// if this is already the last one.
187+
pub fn saturating_next(&self) -> Edition {
188+
use Edition::*;
189+
match self {
190+
Edition2015 => Edition2018,
191+
Edition2018 => Edition2021,
192+
Edition2021 => Edition2021,
193+
}
194+
}
195+
185196
/// Updates the given [`ProcessBuilder`] to include the appropriate flags
186197
/// for setting the edition.
187198
pub(crate) fn cmd_edition_arg(&self, cmd: &mut ProcessBuilder) {

src/cargo/ops/fix.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ use crate::util::{existing_vcs_repo, LockServer, LockServerClient};
5959

6060
const FIX_ENV: &str = "__CARGO_FIX_PLZ";
6161
const BROKEN_CODE_ENV: &str = "__CARGO_FIX_BROKEN_CODE";
62-
const PREPARE_FOR_ENV: &str = "__CARGO_FIX_PREPARE_FOR";
6362
const EDITION_ENV: &str = "__CARGO_FIX_EDITION";
6463
const IDIOMS_ENV: &str = "__CARGO_FIX_IDIOMS";
6564

66-
pub struct FixOptions<'a> {
65+
pub struct FixOptions {
6766
pub edition: bool,
68-
pub prepare_for: Option<&'a str>,
6967
pub idioms: bool,
7068
pub compile_opts: CompileOptions,
7169
pub allow_dirty: bool,
@@ -74,7 +72,7 @@ pub struct FixOptions<'a> {
7472
pub broken_code: bool,
7573
}
7674

77-
pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
75+
pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
7876
check_version_control(ws.config(), opts)?;
7977

8078
// Spin up our lock server, which our subprocesses will use to synchronize fixes.
@@ -91,8 +89,6 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
9189

9290
if opts.edition {
9391
wrapper.env(EDITION_ENV, "1");
94-
} else if let Some(edition) = opts.prepare_for {
95-
wrapper.env(PREPARE_FOR_ENV, edition);
9692
}
9793
if opts.idioms {
9894
wrapper.env(IDIOMS_ENV, "1");
@@ -125,7 +121,7 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
125121
Ok(())
126122
}
127123

128-
fn check_version_control(config: &Config, opts: &FixOptions<'_>) -> CargoResult<()> {
124+
fn check_version_control(config: &Config, opts: &FixOptions) -> CargoResult<()> {
129125
if opts.allow_no_vcs {
130126
return Ok(());
131127
}
@@ -647,17 +643,11 @@ impl FixArgs {
647643
let file = file.ok_or_else(|| anyhow::anyhow!("could not find .rs file in rustc args"))?;
648644
let idioms = env::var(IDIOMS_ENV).is_ok();
649645

650-
let prepare_for_edition = if let Ok(s) = env::var(PREPARE_FOR_ENV) {
651-
Some(s.parse()?)
652-
} else if env::var(EDITION_ENV).is_ok() {
653-
match enabled_edition {
654-
None | Some(Edition::Edition2015) => Some(Edition::Edition2018),
655-
Some(Edition::Edition2018) => Some(Edition::Edition2021),
656-
Some(Edition::Edition2021) => Some(Edition::Edition2021),
657-
}
658-
} else {
659-
None
660-
};
646+
let prepare_for_edition = env::var(EDITION_ENV).ok().map(|_| {
647+
enabled_edition
648+
.unwrap_or(Edition::Edition2015)
649+
.saturating_next()
650+
});
661651

662652
Ok(FixArgs {
663653
file,

tests/testsuite/fix.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ fn fix_overlapping() {
986986
)
987987
.build();
988988

989-
p.cargo("fix --allow-no-vcs --prepare-for 2018 --lib")
989+
p.cargo("fix --allow-no-vcs --edition --lib")
990990
.with_stderr(
991991
"\
992992
[CHECKING] foo [..]
@@ -1044,25 +1044,6 @@ fn idioms_2015_ok() {
10441044
p.cargo("fix --edition-idioms --allow-no-vcs").run();
10451045
}
10461046

1047-
#[cargo_test]
1048-
fn both_edition_migrate_flags() {
1049-
let p = project().file("src/lib.rs", "").build();
1050-
1051-
let stderr = "\
1052-
error: The argument '--edition' cannot be used with '--prepare-for <prepare-for>'
1053-
1054-
USAGE:
1055-
cargo[..] fix --edition
1056-
1057-
For more information try --help
1058-
";
1059-
1060-
p.cargo("fix --prepare-for 2018 --edition")
1061-
.with_status(1)
1062-
.with_stderr(stderr)
1063-
.run();
1064-
}
1065-
10661047
#[cargo_test]
10671048
fn shows_warnings_on_second_run_without_changes() {
10681049
let p = project()

0 commit comments

Comments
 (0)