Skip to content

Commit ac58670

Browse files
committed
Auto merge of #9800 - ehuss:stabilize-2021, r=alexcrichton
Stabilize 2021 edition This stabilizes the 2021 edition. Closes #9781
2 parents 72aee9e + 68753e2 commit ac58670

File tree

15 files changed

+62
-60
lines changed

15 files changed

+62
-60
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub struct TargetInfo {
4747
pub rustdocflags: Vec<String>,
4848
/// Whether or not rustc supports the `-Csplit-debuginfo` flag.
4949
pub supports_split_debuginfo: bool,
50+
/// Whether or not rustc supports the `--force-warn` flag. Remove after 1.56 is stable.
51+
pub supports_force_warn: bool,
5052
}
5153

5254
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -178,6 +180,12 @@ impl TargetInfo {
178180
extra_fingerprint,
179181
)
180182
.is_ok();
183+
let supports_force_warn = rustc
184+
.cached_output(
185+
process.clone().arg("--force-warn=rust-2021-compatibility"),
186+
extra_fingerprint,
187+
)
188+
.is_ok();
181189

182190
process.arg("--print=sysroot");
183191
process.arg("--print=cfg");
@@ -253,6 +261,7 @@ impl TargetInfo {
253261
)?,
254262
cfg,
255263
supports_split_debuginfo,
264+
supports_force_warn,
256265
})
257266
}
258267

src/cargo/core/features.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub enum Edition {
139139
// - Set LATEST_STABLE to the new version.
140140
// - Update `is_stable` to `true`.
141141
// - Set the editionNNNN feature to stable in the features macro below.
142+
// - Update any tests that are affected.
142143
// - Update the man page for the --edition flag.
143144
// - Update unstable.md to move the edition section to the bottom.
144145
// - Update the documentation:
@@ -150,9 +151,9 @@ impl Edition {
150151
/// The latest edition that is unstable.
151152
///
152153
/// This is `None` if there is no next unstable edition.
153-
pub const LATEST_UNSTABLE: Option<Edition> = Some(Edition::Edition2021);
154+
pub const LATEST_UNSTABLE: Option<Edition> = None;
154155
/// The latest stable edition.
155-
pub const LATEST_STABLE: Edition = Edition::Edition2018;
156+
pub const LATEST_STABLE: Edition = Edition::Edition2021;
156157
/// Possible values allowed for the `--edition` CLI flag.
157158
///
158159
/// This requires a static value due to the way clap works, otherwise I
@@ -176,7 +177,7 @@ impl Edition {
176177
match self {
177178
Edition2015 => true,
178179
Edition2018 => true,
179-
Edition2021 => false,
180+
Edition2021 => true,
180181
}
181182
}
182183

@@ -398,7 +399,7 @@ features! {
398399
(stable, rust_version, "1.56", "reference/manifest.html#the-rust-version-field"),
399400

400401
// Support for 2021 edition.
401-
(unstable, edition2021, "", "reference/unstable.html#edition-2021"),
402+
(stable, edition2021, "1.56", "reference/manifest.html#the-edition-field"),
402403

403404
// Allow to specify per-package targets (compile kinds)
404405
(unstable, per_package_target, "", "reference/unstable.html#per-package-target"),

src/cargo/ops/fix.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use log::{debug, trace, warn};
5151
use rustfix::diagnostics::Diagnostic;
5252
use rustfix::{self, CodeFix};
5353

54-
use crate::core::compiler::RustcTargetData;
54+
use crate::core::compiler::{CompileKind, RustcTargetData, TargetInfo};
5555
use crate::core::resolver::features::{DiffMap, FeatureOpts, FeatureResolver};
5656
use crate::core::resolver::{HasDevUnits, Resolve, ResolveBehavior};
5757
use crate::core::{Edition, MaybePackage, Workspace};
@@ -67,6 +67,7 @@ const FIX_ENV: &str = "__CARGO_FIX_PLZ";
6767
const BROKEN_CODE_ENV: &str = "__CARGO_FIX_BROKEN_CODE";
6868
const EDITION_ENV: &str = "__CARGO_FIX_EDITION";
6969
const IDIOMS_ENV: &str = "__CARGO_FIX_IDIOMS";
70+
const SUPPORTS_FORCE_WARN: &str = "__CARGO_SUPPORTS_FORCE_WARN";
7071

7172
pub struct FixOptions {
7273
pub edition: bool,
@@ -122,6 +123,17 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
122123
let rustc = ws.config().load_global_rustc(Some(ws))?;
123124
wrapper.arg(&rustc.path);
124125

126+
// Remove this once 1.56 is stabilized.
127+
let target_info = TargetInfo::new(
128+
ws.config(),
129+
&opts.compile_opts.build_config.requested_kinds,
130+
&rustc,
131+
CompileKind::Host,
132+
)?;
133+
if target_info.supports_force_warn {
134+
wrapper.env(SUPPORTS_FORCE_WARN, "1");
135+
}
136+
125137
// primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
126138
// repeating build until there are no more changes to be applied
127139
opts.compile_opts.build_config.primary_unit_rustc = Some(wrapper);
@@ -362,7 +374,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
362374
// that we have to back it all out.
363375
if !fixes.files.is_empty() {
364376
let mut cmd = rustc.build_command();
365-
args.apply(&mut cmd, config);
377+
args.apply(&mut cmd);
366378
cmd.arg("--error-format=json");
367379
debug!("calling rustc for final verification: {:?}", cmd);
368380
let output = cmd.output().context("failed to spawn rustc")?;
@@ -403,7 +415,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
403415
// - If `--broken-code`, show the error messages.
404416
// - If the fix succeeded, show any remaining warnings.
405417
let mut cmd = rustc.build_command();
406-
args.apply(&mut cmd, config);
418+
args.apply(&mut cmd);
407419
for arg in args.format_args {
408420
// Add any json/error format arguments that Cargo wants. This allows
409421
// things like colored output to work correctly.
@@ -497,7 +509,7 @@ fn rustfix_crate(
497509
// We'll generate new errors below.
498510
file.errors_applying_fixes.clear();
499511
}
500-
rustfix_and_fix(&mut fixes, rustc, filename, args, config)?;
512+
rustfix_and_fix(&mut fixes, rustc, filename, args)?;
501513
let mut progress_yet_to_be_made = false;
502514
for (path, file) in fixes.files.iter_mut() {
503515
if file.errors_applying_fixes.is_empty() {
@@ -539,15 +551,14 @@ fn rustfix_and_fix(
539551
rustc: &ProcessBuilder,
540552
filename: &Path,
541553
args: &FixArgs,
542-
config: &Config,
543554
) -> Result<(), Error> {
544555
// If not empty, filter by these lints.
545556
// TODO: implement a way to specify this.
546557
let only = HashSet::new();
547558

548559
let mut cmd = rustc.build_command();
549560
cmd.arg("--error-format=json");
550-
args.apply(&mut cmd, config);
561+
args.apply(&mut cmd);
551562
debug!(
552563
"calling rustc to collect suggestions and validate previous fixes: {:?}",
553564
cmd
@@ -822,10 +833,10 @@ impl FixArgs {
822833
})
823834
}
824835

825-
fn apply(&self, cmd: &mut Command, config: &Config) {
836+
fn apply(&self, cmd: &mut Command) {
826837
cmd.arg(&self.file);
827838
cmd.args(&self.other);
828-
if self.prepare_for_edition.is_some() && config.nightly_features_allowed {
839+
if self.prepare_for_edition.is_some() && env::var_os(SUPPORTS_FORCE_WARN).is_some() {
829840
// When migrating an edition, we don't want to fix other lints as
830841
// they can sometimes add suggestions that fail to apply, causing
831842
// the entire migration to fail. But those lints aren't needed to
@@ -844,7 +855,7 @@ impl FixArgs {
844855

845856
if let Some(edition) = self.prepare_for_edition {
846857
if edition.supports_compat_lint() {
847-
if config.nightly_features_allowed {
858+
if env::var_os(SUPPORTS_FORCE_WARN).is_some() {
848859
cmd.arg("--force-warn")
849860
.arg(format!("rust-{}-compatibility", edition))
850861
.arg("-Zunstable-options");

src/doc/man/generated_txt/cargo-init.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ OPTIONS
3030
Create a package with a library target (src/lib.rs).
3131

3232
--edition edition
33-
Specify the Rust edition to use. Default is 2018. Possible values:
33+
Specify the Rust edition to use. Default is 2021. Possible values:
3434
2015, 2018, 2021
3535

3636
--name name

src/doc/man/generated_txt/cargo-new.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ OPTIONS
2525
Create a package with a library target (src/lib.rs).
2626

2727
--edition edition
28-
Specify the Rust edition to use. Default is 2018. Possible values:
28+
Specify the Rust edition to use. Default is 2021. Possible values:
2929
2015, 2018, 2021
3030

3131
--name name

src/doc/man/includes/options-new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Create a package with a library target (`src/lib.rs`).
1010
{{/option}}
1111

1212
{{#option "`--edition` _edition_" }}
13-
Specify the Rust edition to use. Default is 2018.
13+
Specify the Rust edition to use. Default is 2021.
1414
Possible values: 2015, 2018, 2021
1515
{{/option}}
1616

src/doc/src/commands/cargo-init.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This is the default behavior.</dd>
3939

4040

4141
<dt class="option-term" id="option-cargo-init---edition"><a class="option-anchor" href="#option-cargo-init---edition"></a><code>--edition</code> <em>edition</em></dt>
42-
<dd class="option-desc">Specify the Rust edition to use. Default is 2018.
42+
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
4343
Possible values: 2015, 2018, 2021</dd>
4444

4545

src/doc/src/commands/cargo-new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This is the default behavior.</dd>
3434

3535

3636
<dt class="option-term" id="option-cargo-new---edition"><a class="option-anchor" href="#option-cargo-new---edition"></a><code>--edition</code> <em>edition</em></dt>
37-
<dd class="option-desc">Specify the Rust edition to use. Default is 2018.
37+
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
3838
Possible values: 2015, 2018, 2021</dd>
3939

4040

src/doc/src/reference/manifest.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ examples, etc.
133133
```toml
134134
[package]
135135
# ...
136-
edition = '2018'
136+
edition = '2021'
137137
```
138138

139139
Most manifests have the `edition` field filled in automatically by [`cargo new`]
140140
with the latest stable edition. By default `cargo new` creates a manifest with
141-
the 2018 edition currently.
141+
the 2021 edition currently.
142142

143143
If the `edition` field is not present in `Cargo.toml`, then the 2015 edition is
144144
assumed for backwards compatibility. Note that all manifests

src/doc/src/reference/resolver.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ version = "1.0.0"
408408
resolver = "2"
409409
```
410410

411-
The version `"1"` resolver is the original resolver that shipped with Cargo up
412-
to version 1.50, and is the default if the `resolver` is not specified.
411+
The version `"1"` resolver is the original resolver that shipped with Cargo up to version 1.50.
412+
The default is `"2"` if the root package specifies [`edition = "2021"`](manifest.md#the-edition-field) or a newer edition.
413+
Otherwise the default is `"1"`.
413414

414415
The version `"2"` resolver introduces changes in [feature
415416
unification](#features). See the [features chapter][features-2] for more

0 commit comments

Comments
 (0)