Skip to content

Commit

Permalink
Auto merge of rust-lang#14110 - epage:edition, r=weihanglo
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 19, 2024
2 parents 99361c4 + bdcf397 commit 93ba1e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@ fn to_real_manifest(
// 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 {
if msrv_edition != default_edition || rust_version.is_none() {
let tip = if msrv_edition == latest_edition || rust_version.is_none() {
format!(" while the latest is {latest_edition}")
} else {
format!(" while {msrv_edition} is compatible with `rust-version`")
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,7 @@ fn artifact_dep_target_specified() {
version = "0.0.0"
authors = []
resolver = "2"
edition = "2015"
[dependencies]
bindep = { path = "bindep", artifact = "bin", target = "$TARGET" }
Expand Down
26 changes: 26 additions & 0 deletions tests/testsuite/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ fn edition_unstable() {
.run();
}

#[cargo_test]
fn unset_edition_with_unset_rust_version() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = 'foo'
version = '0.1.0'
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check -v")
.with_stderr(
"\
[WARNING] no edition set: defaulting to the 2015 edition while the latest is 2021
[CHECKING] foo [..]
[RUNNING] `rustc [..] --edition=2015 [..]`
[FINISHED] [..]
",
)
.run();
}

#[cargo_test]
fn unset_edition_works_with_no_newer_compatible_edition() {
let p = project()
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/shell_quoting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn features_are_quoted() {
name = "foo"
version = "0.1.0"
authors = ["[email protected]"]
edition = "2015"
[features]
some_feature = []
Expand Down

0 comments on commit 93ba1e6

Please sign in to comment.