Skip to content

Commit

Permalink
Add support for Rust edition 2021.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Nov 30, 2020
1 parent 12c107a commit de839da
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 15 deletions.
12 changes: 8 additions & 4 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ pub enum Edition {
Edition2015,
/// The 2018 edition
Edition2018,
/// The 2021 edition
Edition2021,
}

impl fmt::Display for Edition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Edition::Edition2015 => f.write_str("2015"),
Edition::Edition2018 => f.write_str("2018"),
Edition::Edition2021 => f.write_str("2021"),
}
}
}
Expand All @@ -82,14 +85,15 @@ impl FromStr for Edition {
match s {
"2015" => Ok(Edition::Edition2015),
"2018" => Ok(Edition::Edition2018),
s if s.parse().map_or(false, |y: u16| y > 2020 && y < 2050) => bail!(
"2021" => Ok(Edition::Edition2021),
s if s.parse().map_or(false, |y: u16| y > 2021 && y < 2050) => bail!(
"this version of Cargo is older than the `{}` edition, \
and only supports `2015` and `2018` editions.",
and only supports `2015`, `2018`, and `2021` editions.",
s
),
s => bail!(
"supported edition values are `2015` or `2018`, but `{}` \
is unknown",
"supported edition values are `2015`, `2018`, or `2021`, \
but `{}` is unknown",
s
),
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub trait AppExt: Sized {
._arg(opt("lib", "Use a library template"))
._arg(
opt("edition", "Edition to set for the crate generated")
.possible_values(&["2015", "2018"])
.possible_values(&["2015", "2018", "2021"])
.value_name("YEAR"),
)
._arg(
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 @@ -69,7 +69,7 @@ OPTIONS

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

--name name
Set the package name. Defaults to the directory 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 @@ -64,7 +64,7 @@ OPTIONS

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

--name name
Set the package name. Defaults to the directory 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 @@ -11,7 +11,7 @@ Create a package with a library target (`src/lib.rs`).

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

{{#option "`--name` _name_" }}
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 @@ -66,7 +66,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.
Possible values: 2015, 2018</dd>
Possible values: 2015, 2018, 2021</dd>


<dt class="option-term" id="option-cargo-init---name"><a class="option-anchor" href="#option-cargo-init---name"></a><code>--name</code> <em>name</em></dt>
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 @@ -61,7 +61,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.
Possible values: 2015, 2018</dd>
Possible values: 2015, 2018, 2021</dd>


<dt class="option-term" id="option-cargo-new---name"><a class="option-anchor" href="#option-cargo-new---name"></a><code>--name</code> <em>name</em></dt>
Expand Down
2 changes: 1 addition & 1 deletion src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ _cargo() {
init)
_arguments -s -S $common $registry \
'--lib[use library template]' \
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018)' \
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018 2021)' \
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
'--name=[set the resulting package name]:name' \
'1:path:_directories'
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-init.1
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
\fB\-\-edition\fR \fIedition\fR
.RS 4
Specify the Rust edition to use. Default is 2018.
Possible values: 2015, 2018
Possible values: 2015, 2018, 2021
.RE
.sp
\fB\-\-name\fR \fIname\fR
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 @@ -97,7 +97,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
\fB\-\-edition\fR \fIedition\fR
.RS 4
Specify the Rust edition to use. Default is 2018.
Possible values: 2015, 2018
Possible values: 2015, 2018, 2021
.RE
.sp
\fB\-\-name\fR \fIname\fR
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ Caused by:
failed to parse the `edition` key
Caused by:
supported edition values are `2015` or `2018`, but `chicken` is unknown
supported edition values are `2015`, `2018`, or `2021`, but `chicken` is unknown
"
.to_string(),
)
Expand Down Expand Up @@ -1075,7 +1075,7 @@ Caused by:
failed to parse the `edition` key
Caused by:
this version of Cargo is older than the `2038` edition, and only supports `2015` and `2018` editions.
this version of Cargo is older than the `2038` edition, and only supports `2015`, `2018`, and `2021` editions.
"
.to_string(),
)
Expand Down

0 comments on commit de839da

Please sign in to comment.