Skip to content

Commit 19141bd

Browse files
committed
Auto merge of #13533 - epage:edition-warn, r=weihanglo
fix(toml): Don't warn on unset Edition if only 2015 is compatible ### What does this PR try to resolve? The warning doesn't help towards the stated goal if the only MSRV-compatible Edition is 2015 (plus, if you're MSRV is that old, you likely know better). This also fixes a problem in #13505 where we were suggesting to set a field that might require an MSRV bump which may be unactionable to silence and we avoid warnings without an actionable way of silencing until #12235 gives us a general means. ### How should we test and review this PR? ### Additional information This was discussed in - #13505 - https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/warn.20on.20missing.20.60edition.60.20field.20in.20Cargo.2Etoml
2 parents a0cad1e + 3071f88 commit 19141bd

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,16 +617,20 @@ pub fn to_real_manifest(
617617
let default_edition = Edition::default();
618618
let latest_edition = Edition::LATEST_STABLE;
619619

620-
let tip = if msrv_edition == default_edition {
621-
String::new()
622-
} else if msrv_edition == latest_edition {
623-
format!(" while the latest is {latest_edition}")
624-
} else {
625-
format!(" while {msrv_edition} is compatible with `rust-version`")
626-
};
627-
warnings.push(format!(
628-
"no edition set: defaulting to the {default_edition} edition{tip}",
629-
));
620+
// We're trying to help the user who might assume they are using a new edition,
621+
// so if they can't use a new edition, don't bother to tell them to set it.
622+
// This also avoids having to worry about whether `package.edition` is compatible with
623+
// their MSRV.
624+
if msrv_edition != default_edition {
625+
let tip = if msrv_edition == latest_edition {
626+
format!(" while the latest is {latest_edition}")
627+
} else {
628+
format!(" while {msrv_edition} is compatible with `rust-version`")
629+
};
630+
warnings.push(format!(
631+
"no edition set: defaulting to the {default_edition} edition{tip}",
632+
));
633+
}
630634
default_edition
631635
};
632636
// Add these lines if start a new unstable edition.

tests/testsuite/edition.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ fn unset_edition_works_with_no_newer_compatible_edition() {
141141
p.cargo("check -v")
142142
.with_stderr(
143143
"\
144-
[WARNING] no edition set: defaulting to the 2015 edition
145144
[CHECKING] foo [..]
146145
[RUNNING] `rustc [..] --edition=2015 [..]`
147146
[FINISHED] [..]

0 commit comments

Comments
 (0)