Skip to content

Commit b04345c

Browse files
committed
Auto merge of #8122 - kornelski:future-edition, r=Eh2406
Hint upgrading for future edition keys A more specific error message for potentially-future edition values. This error is likely to be seen by people who are not regular Rust users and are just trying to build someone's crate. It may be helpful to stronger hint at upgrading Cargo, rather than display a more general message about an unknown value. I know Cargo plans to fix it better with explicit MSRV eventually, but that's not ready yet, so it's better to land something sooner.
2 parents 85fd286 + f57c4c9 commit b04345c

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
@@ -1066,6 +1066,38 @@ Caused by:
10661066
.run();
10671067
}
10681068

1069+
#[cargo_test]
1070+
fn test_edition_from_the_future() {
1071+
let p = project()
1072+
.file(
1073+
"Cargo.toml",
1074+
r#"[package]
1075+
edition = "2038"
1076+
name = "foo"
1077+
version = "99.99.99"
1078+
authors = []
1079+
"#,
1080+
)
1081+
.file("src/main.rs", r#""#)
1082+
.build();
1083+
1084+
p.cargo("build")
1085+
.with_status(101)
1086+
.with_stderr(
1087+
"\
1088+
error: failed to parse manifest at `[..]`
1089+
1090+
Caused by:
1091+
failed to parse the `edition` key
1092+
1093+
Caused by:
1094+
this version of Cargo is older than the `2038` edition, and only supports `2015` and `2018` editions.
1095+
"
1096+
.to_string(),
1097+
)
1098+
.run();
1099+
}
1100+
10691101
#[cargo_test]
10701102
fn do_not_package_if_src_was_modified() {
10711103
let p = project()

0 commit comments

Comments
 (0)