Skip to content

Commit f57c4c9

Browse files
committed
Hint upgrading for future edition keys
1 parent f9047dc commit f57c4c9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/cargo/core/features.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ impl FromStr for Edition {
8282
match s {
8383
"2015" => Ok(Edition::Edition2015),
8484
"2018" => Ok(Edition::Edition2018),
85+
s if s.parse().map_or(false, |y: u16| y > 2020 && y < 2050) => bail!(
86+
"this version of Cargo is older than the `{}` edition, \
87+
and only supports `2015` and `2018` editions.",
88+
s
89+
),
8590
s => bail!(
8691
"supported edition values are `2015` or `2018`, but `{}` \
8792
is unknown",

tests/testsuite/package.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,38 @@ Caused by:
10861086
.run();
10871087
}
10881088

1089+
#[cargo_test]
1090+
fn test_edition_from_the_future() {
1091+
let p = project()
1092+
.file(
1093+
"Cargo.toml",
1094+
r#"[package]
1095+
edition = "2038"
1096+
name = "foo"
1097+
version = "99.99.99"
1098+
authors = []
1099+
"#,
1100+
)
1101+
.file("src/main.rs", r#""#)
1102+
.build();
1103+
1104+
p.cargo("build")
1105+
.with_status(101)
1106+
.with_stderr(
1107+
"\
1108+
error: failed to parse manifest at `[..]`
1109+
1110+
Caused by:
1111+
failed to parse the `edition` key
1112+
1113+
Caused by:
1114+
this version of Cargo is older than the `2038` edition, and only supports `2015` and `2018` editions.
1115+
"
1116+
.to_string(),
1117+
)
1118+
.run();
1119+
}
1120+
10891121
#[cargo_test]
10901122
fn do_not_package_if_src_was_modified() {
10911123
let p = project()

0 commit comments

Comments
 (0)