Skip to content

Commit de839da

Browse files
committed
Add support for Rust edition 2021.
1 parent 12c107a commit de839da

File tree

11 files changed

+19
-15
lines changed

11 files changed

+19
-15
lines changed

src/cargo/core/features.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ pub enum Edition {
6666
Edition2015,
6767
/// The 2018 edition
6868
Edition2018,
69+
/// The 2021 edition
70+
Edition2021,
6971
}
7072

7173
impl fmt::Display for Edition {
7274
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7375
match *self {
7476
Edition::Edition2015 => f.write_str("2015"),
7577
Edition::Edition2018 => f.write_str("2018"),
78+
Edition::Edition2021 => f.write_str("2021"),
7679
}
7780
}
7881
}
@@ -82,14 +85,15 @@ impl FromStr for Edition {
8285
match s {
8386
"2015" => Ok(Edition::Edition2015),
8487
"2018" => Ok(Edition::Edition2018),
85-
s if s.parse().map_or(false, |y: u16| y > 2020 && y < 2050) => bail!(
88+
"2021" => Ok(Edition::Edition2021),
89+
s if s.parse().map_or(false, |y: u16| y > 2021 && y < 2050) => bail!(
8690
"this version of Cargo is older than the `{}` edition, \
87-
and only supports `2015` and `2018` editions.",
91+
and only supports `2015`, `2018`, and `2021` editions.",
8892
s
8993
),
9094
s => bail!(
91-
"supported edition values are `2015` or `2018`, but `{}` \
92-
is unknown",
95+
"supported edition values are `2015`, `2018`, or `2021`, \
96+
but `{}` is unknown",
9397
s
9498
),
9599
}

src/cargo/util/command_prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub trait AppExt: Sized {
188188
._arg(opt("lib", "Use a library template"))
189189
._arg(
190190
opt("edition", "Edition to set for the crate generated")
191-
.possible_values(&["2015", "2018"])
191+
.possible_values(&["2015", "2018", "2021"])
192192
.value_name("YEAR"),
193193
)
194194
._arg(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ OPTIONS
6969

7070
--edition edition
7171
Specify the Rust edition to use. Default is 2018. Possible values:
72-
2015, 2018
72+
2015, 2018, 2021
7373

7474
--name name
7575
Set the package name. Defaults to the directory name.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ OPTIONS
6464

6565
--edition edition
6666
Specify the Rust edition to use. Default is 2018. Possible values:
67-
2015, 2018
67+
2015, 2018, 2021
6868

6969
--name name
7070
Set the package name. Defaults to the directory name.

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

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

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

1717
{{#option "`--name` _name_" }}

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

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

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

7171

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

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

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

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

6666

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

src/etc/_cargo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ _cargo() {
136136
init)
137137
_arguments -s -S $common $registry \
138138
'--lib[use library template]' \
139-
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018)' \
139+
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018 2021)' \
140140
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
141141
'--name=[set the resulting package name]:name' \
142142
'1:path:_directories'

src/etc/man/cargo-init.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
102102
\fB\-\-edition\fR \fIedition\fR
103103
.RS 4
104104
Specify the Rust edition to use. Default is 2018.
105-
Possible values: 2015, 2018
105+
Possible values: 2015, 2018, 2021
106106
.RE
107107
.sp
108108
\fB\-\-name\fR \fIname\fR

src/etc/man/cargo-new.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Create a package with a library target (\fBsrc/lib.rs\fR).
9797
\fB\-\-edition\fR \fIedition\fR
9898
.RS 4
9999
Specify the Rust edition to use. Default is 2018.
100-
Possible values: 2015, 2018
100+
Possible values: 2015, 2018, 2021
101101
.RE
102102
.sp
103103
\fB\-\-name\fR \fIname\fR

tests/testsuite/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ Caused by:
10431043
failed to parse the `edition` key
10441044
10451045
Caused by:
1046-
supported edition values are `2015` or `2018`, but `chicken` is unknown
1046+
supported edition values are `2015`, `2018`, or `2021`, but `chicken` is unknown
10471047
"
10481048
.to_string(),
10491049
)
@@ -1075,7 +1075,7 @@ Caused by:
10751075
failed to parse the `edition` key
10761076
10771077
Caused by:
1078-
this version of Cargo is older than the `2038` edition, and only supports `2015` and `2018` editions.
1078+
this version of Cargo is older than the `2038` edition, and only supports `2015`, `2018`, and `2021` editions.
10791079
"
10801080
.to_string(),
10811081
)

0 commit comments

Comments
 (0)