feat(resolver): Add default Edition2024 to resolver v3

This commit is contained in:
Ed Page 2024-04-18 12:03:56 -05:00
parent 706f8a71c8
commit 9ee41598e8
4 changed files with 116 additions and 2 deletions

View File

@ -300,7 +300,9 @@ impl Edition {
}
pub(crate) fn default_resolve_behavior(&self) -> ResolveBehavior {
if *self >= Edition::Edition2021 {
if *self >= Edition::Edition2024 {
ResolveBehavior::V3
} else if *self >= Edition::Edition2021 {
ResolveBehavior::V2
} else {
ResolveBehavior::V1

View File

@ -339,6 +339,7 @@ This was stabilized in 1.79 in [#13608](https://github.com/rust-lang/cargo/pull/
`-Zmsrv-policy` allows access to an MSRV-aware resolver which can be enabled with:
- `resolver.something-like-precedence` config field
- `workspace.resolver = "3"` / `package.resolver = "3"`
- `package.edition = "2024"` (only in workspace root)
The resolver will prefer dependencies with a `package.rust-version` that is the same or older than your project's MSRV.
Your project's MSRV is determined by taking the lowest `package.rust-version` set among your workspace members.

View File

@ -20,7 +20,7 @@
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Locking</tspan><tspan> 2 packages to latest compatible versions</tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Locking</tspan><tspan> 2 packages to latest Rust [..] compatible versions</tspan>
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Checking</tspan><tspan> foo v0.1.0 ([ROOT]/foo)</tspan>
</tspan>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -613,6 +613,117 @@ foo v0.0.1 ([CWD])
.run();
}
#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")]
fn resolve_edition2024() {
Package::new("only-newer", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("newer-and-older", "1.5.0")
.rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("newer-and-older", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition2024"]
[package]
name = "foo"
version = "0.0.1"
edition = "2024"
authors = []
rust-version = "1.60.0"
[dependencies]
only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#,
)
.file("src/main.rs", "fn main(){}")
.build();
// Edition2024 should resolve for MSRV
p.cargo("generate-lockfile")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["edition2024", "msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest Rust 1.60.0 compatible versions
[ADDING] newer-and-older v1.5.0 (latest: v1.6.0)
",
)
.run();
p.cargo("tree")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["edition2024", "msrv-policy"])
.with_stdout(
"\
foo v0.0.1 ([CWD])
newer-and-older v1.5.0
only-newer v1.6.0
",
)
.run();
// `--ignore-rust-version` has precedence over Edition2024
p.cargo("generate-lockfile --ignore-rust-version")
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
",
)
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.run();
p.cargo("tree")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["edition2024", "msrv-policy"])
.with_stdout(
"\
foo v0.0.1 ([CWD])
newer-and-older v1.6.0
only-newer v1.6.0
",
)
.run();
// config has precedence over Edition2024
p.cargo("generate-lockfile")
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-maximum",
)
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
",
)
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.run();
p.cargo("tree")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["edition2024", "msrv-policy"])
.with_stdout(
"\
foo v0.0.1 ([CWD])
newer-and-older v1.6.0
only-newer v1.6.0
",
)
.run();
}
#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")]
fn resolve_v3() {
Package::new("only-newer", "1.6.0")