Add support for Rust edition 2021.

This commit is contained in:
Mara Bos 2020-11-30 20:09:38 +01:00
parent 12c107ade5
commit de839dabe3
11 changed files with 19 additions and 15 deletions

View file

@ -66,6 +66,8 @@ pub enum Edition {
Edition2015,
/// The 2018 edition
Edition2018,
/// The 2021 edition
Edition2021,
}
impl fmt::Display for Edition {
@ -73,6 +75,7 @@ impl fmt::Display for Edition {
match *self {
Edition::Edition2015 => f.write_str("2015"),
Edition::Edition2018 => f.write_str("2018"),
Edition::Edition2021 => f.write_str("2021"),
}
}
}
@ -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
),
}

View file

@ -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(

View file

@ -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.

View file

@ -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.

View file

@ -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_" }}

View file

@ -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>

View file

@ -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>

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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(),
)
@ -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(),
)