From feecbd72a0b429f518e6448ddcd3cadc16ad7b49 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 24 Jul 2024 08:00:21 -0500 Subject: [PATCH] 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 | 16 ++-- .../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, 44 insertions(+), 119 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 4ac8777bd62c..65b14233315d 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 c4fa1a5947db..a8fee94d5e4c 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 d7e970128dae..053ddcc0e180 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,18 @@ 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 +Select how packages with incompatible rust-versions should be resolved. Values include: +- `allow`: treat them like any other dependency +- `fallback`: only consider them if no other dependency 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 above any version that is rust-version compatible - 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 37770685b11b..824973464fd0 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 e88720284607..6936642f491f 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 f20b4c4895b7..8091a1c69bb8 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 f20b4c4895b7..8091a1c69bb8 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 7fea1e6bbb3f..1a4719a5cbe4 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 892e423fcdb1..d2bb3ebabb19 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 56b919e09ea0..11a3b42167ea 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 56b919e09ea0..11a3b42167ea 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 4250ea7c82b1..3d696fc33455 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"])