Skip to content

Commit

Permalink
fix(toml): Don't warn on unset Edition if only 2015 is compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
epage authored and charmitro committed Sep 13, 2024
1 parent 816e53a commit 7789470
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,16 +617,20 @@ pub fn to_real_manifest(
let default_edition = Edition::default();
let latest_edition = Edition::LATEST_STABLE;

let tip = if msrv_edition == default_edition {
String::new()
} else if msrv_edition == latest_edition {
format!(" while the latest is {latest_edition}")
} else {
format!(" while {msrv_edition} is compatible with `rust-version`")
};
warnings.push(format!(
"no edition set: defaulting to the {default_edition} edition{tip}",
));
// We're trying to help the user who might assume they are using a new edition,
// so if they can't use a new edition, don't bother to tell them to set it.
// This also avoids having to worry about whether `package.edition` is compatible with
// their MSRV.
if msrv_edition != default_edition {
let tip = if msrv_edition == latest_edition {
format!(" while the latest is {latest_edition}")
} else {
format!(" while {msrv_edition} is compatible with `rust-version`")
};
warnings.push(format!(
"no edition set: defaulting to the {default_edition} edition{tip}",
));
}
default_edition
};
// Add these lines if start a new unstable edition.
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ fn unset_edition_works_with_no_newer_compatible_edition() {
p.cargo("check -v")
.with_stderr(
"\
[WARNING] no edition set: defaulting to the 2015 edition
[CHECKING] foo [..]
[RUNNING] `rustc [..] --edition=2015 [..]`
[FINISHED] [..]
Expand Down

0 comments on commit 7789470

Please sign in to comment.