Skip to content

Commit 93ba1e6

Browse files
committed
Auto merge of rust-lang#14110 - epage:edition, r=weihanglo
fix(toml): Warn when edition is unuset, even when MSRV is unset ### What does this PR try to resolve? This came up in rust-lang#14108. This got overlooked when we added the MSRV limits to the warning. Users can silence this by setting a very old MSRV. I didn't bother finding a way to word a specialized message for this. Wording for this case seemed hard and I figure someone in this situation knows how to resolve it. Instead, we are targeting the majority of users who aren't setting a `package.rust-version` in the first place. ### How should we test and review this PR? ### Additional information
2 parents 99361c4 + bdcf397 commit 93ba1e6

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/cargo/util/toml/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1154,8 +1154,8 @@ fn to_real_manifest(
11541154
// so if they can't use a new edition, don't bother to tell them to set it.
11551155
// This also avoids having to worry about whether `package.edition` is compatible with
11561156
// their MSRV.
1157-
if msrv_edition != default_edition {
1158-
let tip = if msrv_edition == latest_edition {
1157+
if msrv_edition != default_edition || rust_version.is_none() {
1158+
let tip = if msrv_edition == latest_edition || rust_version.is_none() {
11591159
format!(" while the latest is {latest_edition}")
11601160
} else {
11611161
format!(" while {msrv_edition} is compatible with `rust-version`")

tests/testsuite/artifact_dep.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,7 @@ fn artifact_dep_target_specified() {
15441544
version = "0.0.0"
15451545
authors = []
15461546
resolver = "2"
1547+
edition = "2015"
15471548
15481549
[dependencies]
15491550
bindep = { path = "bindep", artifact = "bin", target = "$TARGET" }

tests/testsuite/edition.rs

+26
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,32 @@ fn edition_unstable() {
125125
.run();
126126
}
127127

128+
#[cargo_test]
129+
fn unset_edition_with_unset_rust_version() {
130+
let p = project()
131+
.file(
132+
"Cargo.toml",
133+
r#"
134+
[package]
135+
name = 'foo'
136+
version = '0.1.0'
137+
"#,
138+
)
139+
.file("src/lib.rs", "")
140+
.build();
141+
142+
p.cargo("check -v")
143+
.with_stderr(
144+
"\
145+
[WARNING] no edition set: defaulting to the 2015 edition while the latest is 2021
146+
[CHECKING] foo [..]
147+
[RUNNING] `rustc [..] --edition=2015 [..]`
148+
[FINISHED] [..]
149+
",
150+
)
151+
.run();
152+
}
153+
128154
#[cargo_test]
129155
fn unset_edition_works_with_no_newer_compatible_edition() {
130156
let p = project()

tests/testsuite/shell_quoting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn features_are_quoted() {
1515
name = "foo"
1616
version = "0.1.0"
1717
authors = ["[email protected]"]
18+
edition = "2015"
1819
1920
[features]
2021
some_feature = []

0 commit comments

Comments
 (0)