Skip to content

Commit

Permalink
Stabilize 2021 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Sep 1, 2021
1 parent 72aee9e commit e6a783a
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 45 deletions.
8 changes: 4 additions & 4 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ impl Edition {
/// The latest edition that is unstable.
///
/// This is `None` if there is no next unstable edition.
pub const LATEST_UNSTABLE: Option<Edition> = Some(Edition::Edition2021);
pub const LATEST_UNSTABLE: Option<Edition> = None;
/// The latest stable edition.
pub const LATEST_STABLE: Edition = Edition::Edition2018;
pub const LATEST_STABLE: Edition = Edition::Edition2021;
/// Possible values allowed for the `--edition` CLI flag.
///
/// This requires a static value due to the way clap works, otherwise I
Expand All @@ -176,7 +176,7 @@ impl Edition {
match self {
Edition2015 => true,
Edition2018 => true,
Edition2021 => false,
Edition2021 => true,
}
}

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

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

// Allow to specify per-package targets (compile kinds)
(unstable, per_package_target, "", "reference/unstable.html#per-package-target"),
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/generated_txt/cargo-init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ OPTIONS
Create a package with a library target (src/lib.rs).

--edition edition
Specify the Rust edition to use. Default is 2018. Possible values:
Specify the Rust edition to use. Default is 2021. Possible values:
2015, 2018, 2021

--name name
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/generated_txt/cargo-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OPTIONS
Create a package with a library target (src/lib.rs).

--edition edition
Specify the Rust edition to use. Default is 2018. Possible values:
Specify the Rust edition to use. Default is 2021. Possible values:
2015, 2018, 2021

--name name
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/includes/options-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Create a package with a library target (`src/lib.rs`).
{{/option}}

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

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This is the default behavior.</dd>


<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>
<dd class="option-desc">Specify the Rust edition to use. Default is 2018.
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
Possible values: 2015, 2018, 2021</dd>


Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This is the default behavior.</dd>


<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>
<dd class="option-desc">Specify the Rust edition to use. Default is 2018.
<dd class="option-desc">Specify the Rust edition to use. Default is 2021.
Possible values: 2015, 2018, 2021</dd>


Expand Down
4 changes: 2 additions & 2 deletions src/doc/src/reference/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ examples, etc.
```toml
[package]
# ...
edition = '2018'
edition = '2021'
```

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

If the `edition` field is not present in `Cargo.toml`, then the 2015 edition is
assumed for backwards compatibility. Note that all manifests
Expand Down
5 changes: 3 additions & 2 deletions src/doc/src/reference/resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ version = "1.0.0"
resolver = "2"
```

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

The version `"2"` resolver introduces changes in [feature
unification](#features). See the [features chapter][features-2] for more
Expand Down
35 changes: 6 additions & 29 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ Each new feature described below should explain how to use it.
* [Custom named profiles](#custom-named-profiles) — Adds custom named profiles in addition to the standard names.
* [Profile `strip` option](#profile-strip-option) — Forces the removal of debug information and symbols from executables.
* [per-package-target](#per-package-target) — Sets the `--target` to use for each individual package.
* [Edition 2021](#edition-2021) — Adds support for the 2021 Edition.
* Information and metadata
* [Build-plan](#build-plan) — Emits JSON information on which commands will be run.
* [timings](#timings) — Generates a report on how long individual dependencies took to run.
Expand Down Expand Up @@ -1169,34 +1168,6 @@ cargo logout -Z credential-process
[crates.io]: https://crates.io/
[config file]: config.md

### edition 2021
* Tracking Issue: [rust-lang/rust#85811](https://github.com/rust-lang/rust/issues/85811)

Support for the 2021 [edition] can be enabled by adding the `edition2021`
unstable feature to the top of `Cargo.toml`:

```toml
cargo-features = ["edition2021"]

[package]
name = "my-package"
version = "0.1.0"
edition = "2021"
```

If you want to transition an existing project from a previous edition, then
`cargo fix --edition` can be used on the nightly channel. After running `cargo
fix`, you can switch the edition to 2021 as illustrated above.

This feature is very unstable, and is only intended for early testing and
experimentation. Future nightly releases may introduce changes for the 2021
edition that may break your build.

The 2021 edition will set the default [resolver version] to "2".

[edition]: ../../edition-guide/index.html
[resolver version]: resolver.md#resolver-versions

### future incompat report
* RFC: [#2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)
* rustc Tracking Issue: [#71249](https://github.com/rust-lang/rust/issues/71249)
Expand Down Expand Up @@ -1444,3 +1415,9 @@ The `-Z patch-in-config` flag, and the corresponding support for
`[patch]` section in Cargo configuration files has been stabilized in
the 1.56 release. See the [patch field](config.html#patch) for more
information.

### edition 2021

The 2021 edition has been stabilized in the 1.56 release.
See the [`edition` field](manifest.md#the-edition-field) for more information on setting the edition.
See [`cargo fix --edition`](../commands/cargo-fix.md) and [The Edition Guide](../../edition-guide/index.html) for more information on migrating existing projects.
2 changes: 1 addition & 1 deletion src/etc/man/cargo-init.1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
.sp
\fB\-\-edition\fR \fIedition\fR
.RS 4
Specify the Rust edition to use. Default is 2018.
Specify the Rust edition to use. Default is 2021.
Possible values: 2015, 2018, 2021
.RE
.sp
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-new.1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
.sp
\fB\-\-edition\fR \fIedition\fR
.RS 4
Specify the Rust edition to use. Default is 2018.
Specify the Rust edition to use. Default is 2021.
Possible values: 2015, 2018, 2021
.RE
.sp
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ fn new_with_edition_2018() {
fn new_default_edition() {
cargo_process("new foo").run();
let manifest = fs::read_to_string(paths::root().join("foo/Cargo.toml")).unwrap();
assert!(manifest.contains("edition = \"2018\""));
assert!(manifest.contains("edition = \"2021\""));
}

#[cargo_test]
Expand Down

0 comments on commit e6a783a

Please sign in to comment.