From 8622918953b758ad5ff6cab224103061803b9104 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 24 Jul 2024 08:00:21 -0500 Subject: [PATCH 1/3] fix(config): Adjust MSRV resolve config field name / values Fixes #13540 --- src/cargo/core/workspace.rs | 8 +- src/cargo/util/context/mod.rs | 8 +- src/doc/src/reference/unstable.md | 17 ++-- .../cargo_add/rust_version_ignore/mod.rs | 5 +- .../rust_version_incompatible/mod.rs | 5 +- .../cargo_add/rust_version_latest/mod.rs | 5 +- .../cargo_add/rust_version_older/mod.rs | 5 +- tests/testsuite/cargo_add/rustc_ignore/mod.rs | 5 +- .../cargo_add/rustc_incompatible/mod.rs | 5 +- tests/testsuite/cargo_add/rustc_latest/mod.rs | 5 +- tests/testsuite/cargo_add/rustc_older/mod.rs | 5 +- tests/testsuite/rust_version.rs | 91 ++++--------------- 12 files changed, 45 insertions(+), 119 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 4ac8777bd62..65b14233315 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -29,7 +29,7 @@ use crate::util::lints::{ }; use crate::util::toml::{read_manifest, InheritableFields}; use crate::util::{ - context::CargoResolverConfig, context::CargoResolverPrecedence, context::ConfigRelativePath, + context::CargoResolverConfig, context::ConfigRelativePath, context::IncompatibleRustVersions, Filesystem, GlobalContext, IntoUrl, }; use cargo_util::paths; @@ -320,11 +320,11 @@ impl<'gctx> Workspace<'gctx> { } match self.gctx().get::("resolver") { Ok(CargoResolverConfig { - something_like_precedence: Some(precedence), + incompatible_rust_versions: Some(incompatible_rust_versions), }) => { if self.gctx().cli_unstable().msrv_policy { self.resolve_honors_rust_version = - precedence == CargoResolverPrecedence::SomethingLikeRustVersion; + incompatible_rust_versions == IncompatibleRustVersions::Fallback; } else { self.gctx() .shell() @@ -332,7 +332,7 @@ impl<'gctx> Workspace<'gctx> { } } Ok(CargoResolverConfig { - something_like_precedence: None, + incompatible_rust_versions: None, }) => {} Err(err) => { if self.gctx().cli_unstable().msrv_policy { diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index c4fa1a5947d..a8fee94d5e4 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -2680,14 +2680,14 @@ impl BuildTargetConfig { #[derive(Debug, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct CargoResolverConfig { - pub something_like_precedence: Option, + pub incompatible_rust_versions: Option, } #[derive(Debug, Deserialize, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] -pub enum CargoResolverPrecedence { - SomethingLikeMaximum, - SomethingLikeRustVersion, +pub enum IncompatibleRustVersions { + Allow, + Fallback, } #[derive(Deserialize, Default)] diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index d7e970128da..b369642c763 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -338,7 +338,7 @@ This was stabilized in 1.79 in [#13608](https://github.com/rust-lang/cargo/pull/ ### MSRV-aware resolver `-Zmsrv-policy` allows access to an MSRV-aware resolver which can be enabled with: -- `resolver.something-like-precedence` config field +- `resolver.incompatible-rust-versions` config field - `workspace.resolver = "3"` / `package.resolver = "3"` - `package.edition = "2024"` (only in workspace root) @@ -346,18 +346,19 @@ The resolver will prefer dependencies with a `package.rust-version` that is the Your project's MSRV is determined by taking the lowest `package.rust-version` set among your workspace members. If there is none set, your toolchain version will be used with the intent to pick up the version from rustup's `rust-toolchain.toml`, if present. -#### `resolver.something-like-precedence` +#### `resolver.incompatible-rust-versions` * Type: string -* Default: "something-like-maximum" -* Environment: `CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE` +* Default: "allow" +* Environment: `CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS` -Select which policy should be used when resolving dependencies. Values include -- `something-like-maximum`: prefer highest compatible versions of a package -- `something-like-rust-version`: prefer versions of packages compatible with your project's Rust version +When resolving a version for a dependency, select how versions with incompatible `package.rust-version`s are treated. +Values include: +- `allow`: treat `rust-version`-incompatible versions like any other version +- `fallback`: only consider `rust-version`-incompatible versions if no other version matched Can be overridden with - `--ignore-rust-version` CLI option -- Setting the dependency's version requirement too high +- Setting the dependency's version requirement higher than any version with a compatible `rust-version` - Specifying the version to `cargo update` with `--precise` ## precise-pre-release diff --git a/tests/testsuite/cargo_add/rust_version_ignore/mod.rs b/tests/testsuite/cargo_add/rust_version_ignore/mod.rs index 37770685b11..824973464fd 100644 --- a/tests/testsuite/cargo_add/rust_version_ignore/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_ignore/mod.rs @@ -25,10 +25,7 @@ fn case() { .arg("--ignore-rust-version") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .code(0) diff --git a/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs b/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs index e8872028460..6936642f491 100644 --- a/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs @@ -27,10 +27,7 @@ fn case() { .arg("add") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .failure() diff --git a/tests/testsuite/cargo_add/rust_version_latest/mod.rs b/tests/testsuite/cargo_add/rust_version_latest/mod.rs index f20b4c4895b..8091a1c69bb 100644 --- a/tests/testsuite/cargo_add/rust_version_latest/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_latest/mod.rs @@ -24,10 +24,7 @@ fn case() { .arg("add") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() diff --git a/tests/testsuite/cargo_add/rust_version_older/mod.rs b/tests/testsuite/cargo_add/rust_version_older/mod.rs index f20b4c4895b..8091a1c69bb 100644 --- a/tests/testsuite/cargo_add/rust_version_older/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_older/mod.rs @@ -24,10 +24,7 @@ fn case() { .arg("add") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() diff --git a/tests/testsuite/cargo_add/rustc_ignore/mod.rs b/tests/testsuite/cargo_add/rustc_ignore/mod.rs index 7fea1e6bbb3..1a4719a5cbe 100644 --- a/tests/testsuite/cargo_add/rustc_ignore/mod.rs +++ b/tests/testsuite/cargo_add/rustc_ignore/mod.rs @@ -28,10 +28,7 @@ fn case() { .arg("--ignore-rust-version") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .code(0) diff --git a/tests/testsuite/cargo_add/rustc_incompatible/mod.rs b/tests/testsuite/cargo_add/rustc_incompatible/mod.rs index 892e423fcdb..d2bb3ebabb1 100644 --- a/tests/testsuite/cargo_add/rustc_incompatible/mod.rs +++ b/tests/testsuite/cargo_add/rustc_incompatible/mod.rs @@ -21,10 +21,7 @@ fn case() { .arg("add") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .failure() diff --git a/tests/testsuite/cargo_add/rustc_latest/mod.rs b/tests/testsuite/cargo_add/rustc_latest/mod.rs index 56b919e09ea..11a3b42167e 100644 --- a/tests/testsuite/cargo_add/rustc_latest/mod.rs +++ b/tests/testsuite/cargo_add/rustc_latest/mod.rs @@ -27,10 +27,7 @@ fn case() { .arg("add") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() diff --git a/tests/testsuite/cargo_add/rustc_older/mod.rs b/tests/testsuite/cargo_add/rustc_older/mod.rs index 56b919e09ea..11a3b42167e 100644 --- a/tests/testsuite/cargo_add/rustc_older/mod.rs +++ b/tests/testsuite/cargo_add/rustc_older/mod.rs @@ -27,10 +27,7 @@ fn case() { .arg("add") .arg_line("rust-version-user") .current_dir(cwd) - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 4250ea7c82b..3d696fc3345 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -215,10 +215,7 @@ fn resolve_with_rust_version() { .build(); p.cargo("generate-lockfile --ignore-rust-version") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -237,10 +234,7 @@ foo v0.0.1 ([ROOT]/foo) .run(); p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -295,10 +289,7 @@ fn resolve_with_rustc() { .build(); p.cargo("generate-lockfile --ignore-rust-version") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -317,10 +308,7 @@ foo v0.0.1 ([ROOT]/foo) .run(); p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -373,10 +361,7 @@ fn resolve_with_backtracking() { .build(); p.cargo("generate-lockfile --ignore-rust-version") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -396,10 +381,7 @@ foo v0.0.1 ([ROOT]/foo) // Ideally we'd pick `has-rust-version` 1.6.0 which requires backtracking p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -476,10 +458,7 @@ fn resolve_with_multiple_rust_versions() { .build(); p.cargo("generate-lockfile --ignore-rust-version") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -498,10 +477,7 @@ higher v0.0.1 ([ROOT]/foo) .run(); p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -556,10 +532,7 @@ fn resolve_unstable_config_on_stable() { .build(); p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .with_stderr_data(str![[r#" [WARNING] ignoring `resolver` config table without `-Zmsrv-policy` [UPDATING] `dummy-registry` index @@ -577,7 +550,7 @@ foo v0.0.1 ([ROOT]/foo) .run(); p.cargo("generate-lockfile") - .env("CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", "non-existent") + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "non-existent") .with_stderr_data(str![[r#" [WARNING] ignoring `resolver` config table without `-Zmsrv-policy` [UPDATING] `dummy-registry` index @@ -676,10 +649,7 @@ foo v0.0.1 ([ROOT]/foo) // config has precedence over Edition2024 p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-maximum", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "allow") .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 3 packages to latest compatible versions @@ -782,10 +752,7 @@ foo v0.0.1 ([ROOT]/foo) // config has precedence over v3 p.cargo("generate-lockfile") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-maximum", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "allow") .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 3 packages to latest compatible versions @@ -888,10 +855,7 @@ fn update_msrv_resolve() { .build(); p.cargo("update") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -911,10 +875,7 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th "#]]) .run(); p.cargo("update --ignore-rust-version") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -955,10 +916,7 @@ fn update_precise_overrides_msrv_resolver() { .build(); p.cargo("update") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -969,10 +927,7 @@ fn update_precise_overrides_msrv_resolver() { "#]]) .run(); p.cargo("update --precise 1.6.0 bar") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -1018,10 +973,7 @@ fn check_msrv_resolve() { .build(); p.cargo("check --ignore-rust-version") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data( @@ -1051,10 +1003,7 @@ foo v0.0.1 ([ROOT]/foo) std::fs::remove_file(p.root().join("Cargo.lock")).unwrap(); p.cargo("check") - .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", - ) + .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" @@ -1097,8 +1046,8 @@ fn cargo_install_ignores_msrv_config() { cargo_process("install foo") .env( - "CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE", - "something-like-rust-version", + "CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", + "fallback", ) .arg("-Zmsrv-policy") .masquerade_as_nightly_cargo(&["msrv-policy"]) From fa230d4daca1481c6448818e5acda6f7c45131a5 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 30 Jul 2024 12:17:59 -0500 Subject: [PATCH 2/3] docs(unstable): Clarify MSRV resolvers relationship with rustup --- src/doc/src/reference/unstable.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index b369642c763..12b00e2329a 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -344,7 +344,7 @@ This was stabilized in 1.79 in [#13608](https://github.com/rust-lang/cargo/pull/ 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. -If there is none set, your toolchain version will be used with the intent to pick up the version from rustup's `rust-toolchain.toml`, if present. +If there is no MSRV set then your toolchain version will be used, allowing it to pick up the toolchain version from pinned in rustup (e.g. `rust-toolchain.toml`). #### `resolver.incompatible-rust-versions` * Type: string From 48c5f3566d243cf233cbecacd1a9ce41166f4ec8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 30 Jul 2024 12:18:31 -0500 Subject: [PATCH 3/3] docs(unstable): Be consistent in env styling --- src/doc/src/reference/unstable.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 12b00e2329a..a560f8a7f34 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -348,7 +348,7 @@ If there is no MSRV set then your toolchain version will be used, allowing it to #### `resolver.incompatible-rust-versions` * Type: string -* Default: "allow" +* Default: `"allow"` * Environment: `CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS` When resolving a version for a dependency, select how versions with incompatible `package.rust-version`s are treated.