diff --git a/src/bin/cargo/commands/generate_lockfile.rs b/src/bin/cargo/commands/generate_lockfile.rs index 3ad858daaa7..1f0be40fbf1 100644 --- a/src/bin/cargo/commands/generate_lockfile.rs +++ b/src/bin/cargo/commands/generate_lockfile.rs @@ -8,23 +8,13 @@ pub fn cli() -> Command { .arg_silent_suggestion() .arg_manifest_path() .arg_lockfile_path() - .arg_ignore_rust_version_with_help( - "Ignore `rust-version` specification in packages (unstable)", - ) + .arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages") .after_help(color_print::cstr!( "Run `cargo help generate-lockfile` for more detailed information.\n" )) } pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { - if args.honor_rust_version().is_some() { - gctx.cli_unstable().fail_if_stable_opt_custom_z( - "--ignore-rust-version", - 9930, - "msrv-policy", - gctx.cli_unstable().msrv_policy, - )?; - } let ws = args.workspace(gctx)?; ops::generate_lockfile(&ws)?; Ok(()) diff --git a/src/bin/cargo/commands/update.rs b/src/bin/cargo/commands/update.rs index a1733a50487..3b89d037d40 100644 --- a/src/bin/cargo/commands/update.rs +++ b/src/bin/cargo/commands/update.rs @@ -53,24 +53,13 @@ pub fn cli() -> Command { ) .arg_manifest_path() .arg_lockfile_path() - .arg_ignore_rust_version_with_help( - "Ignore `rust-version` specification in packages (unstable)", - ) + .arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages") .after_help(color_print::cstr!( "Run `cargo help update` for more detailed information.\n" )) } pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { - if args.honor_rust_version().is_some() { - gctx.cli_unstable().fail_if_stable_opt_custom_z( - "--ignore-rust-version", - 9930, - "msrv-policy", - gctx.cli_unstable().msrv_policy, - )?; - } - let mut ws = args.workspace(gctx)?; if args.is_present_with_zero_values("package") { diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index ad4ecc3e25f..b2f78df61c1 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -306,31 +306,12 @@ impl<'gctx> Workspace<'gctx> { } } } - match self.gctx().get::("resolver") { - Ok(CargoResolverConfig { - incompatible_rust_versions: Some(incompatible_rust_versions), - }) => { - if self.gctx().cli_unstable().msrv_policy { - self.resolve_honors_rust_version = - incompatible_rust_versions == IncompatibleRustVersions::Fallback; - } else { - self.gctx() - .shell() - .warn("ignoring `resolver` config table without `-Zmsrv-policy`")?; - } - } - Ok(CargoResolverConfig { - incompatible_rust_versions: None, - }) => {} - Err(err) => { - if self.gctx().cli_unstable().msrv_policy { - return Err(err); - } else { - self.gctx() - .shell() - .warn("ignoring `resolver` config table without `-Zmsrv-policy`")?; - } - } + if let CargoResolverConfig { + incompatible_rust_versions: Some(incompatible_rust_versions), + } = self.gctx().get::("resolver")? + { + self.resolve_honors_rust_version = + incompatible_rust_versions == IncompatibleRustVersions::Fallback; } Ok(()) diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index be8bbd24e66..fe3941a7503 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -143,6 +143,9 @@ rpath = false # Sets the rpath linking option. [profile..package.] # Override profile for a package. # Same keys for a normal profile (minus `panic`, `lto`, and `rpath`). +[resolver] +incompatible-rust-versions = "allow" # Specifies how resolver reacts to these + [registries.] # registries other than crates.io index = "…" # URL of the registry index token = "…" # authentication token for the registry @@ -972,6 +975,30 @@ See [rpath](profiles.md#rpath). See [strip](profiles.md#strip). +### `[resolver]` + +The `[resolver]` table overrides [dependency resolution behavior](resolver.md) for local development (e.g. excludes `cargo install`). + +#### `resolver.incompatible-rust-versions` +* Type: string +* Default: `"allow"` +* Environment: `CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS` + +When resolving which version of a dependency to use, 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 higher than any version with a compatible `rust-version` +- Specifying the version to `cargo update` with `--precise` + +See the [resolver](resolver.md#rust-version) chapter for more details. + +> **MSRV:** +> - `allow` is supported on any version +> - `fallback` is respected as of 1.84 ### `[registries]` diff --git a/src/doc/src/reference/resolver.md b/src/doc/src/reference/resolver.md index 21b66898b45..26c22250a50 100644 --- a/src/doc/src/reference/resolver.md +++ b/src/doc/src/reference/resolver.md @@ -73,7 +73,7 @@ Key steps: ### Version numbers -Cargo prefers the highest version currently available. +Generally, Cargo prefers the highest version currently available. For example, if you had a package in the resolve graph with: ```toml @@ -83,6 +83,8 @@ bitflags = "*" If at the time the `Cargo.lock` file is generated, the greatest version of `bitflags` is `1.2.1`, then the package will use `1.2.1`. +For an example of a possible exception, see [Rust version](#rust-version). + ### Version requirements Package specify what versions they support, rejecting all others, through @@ -201,6 +203,88 @@ ecosystem if you publish a SemVer-incompatible version of a popular library. [semver trick]: https://github.com/dtolnay/semver-trick [`downcast_ref`]: ../../std/any/trait.Any.html#method.downcast_ref +### Rust version + +To support developing software with a minimum supported [Rust version], +the resolver can take into account a dependency version's compatibility with your Rust version. +This is controlled by the config field [`resolver.incompatible-rust-versions`]. + +With the `fallback` setting, the resolver will prefer packages with a Rust version that is +equal to or greater than your own Rust version. +For example, you are using Rust 1.85 to develop the following package: +```toml +[package] +name = "my-cli" +rust-version = "1.62" + +[dependencies] +clap = "4.0" # resolves to 4.0.32 +``` +The resolver would pick version 4.0.32 because it has a Rust version of 1.60.0. +- 4.0.0 is not picked because it is a [lower version number](#version-numbers) despite it also having a Rust version of 1.60.0. +- 4.5.20 is not picked because it is incompatible with `my-cli`'s Rust version of 1.62 despite having a much [higher version](#version-numbers) and it has a Rust version of 1.74.0 which is compatible with your 1.85 toolchain. + +If a version requirement does not include a Rust version compatible dependency version, +the resolver won't error but will instead pick a version, even if its potentially suboptimal. +For example, you change the dependency on `clap`: +```toml +[package] +name = "my-cli" +rust-version = "1.62" + +[dependencies] +clap = "4.2" # resolves to 4.5.20 +``` +No version of `clap` matches that [version requirement](#version-requirements) +that is compatible with Rust version 1.62. +The resolver will then pick an incompatible version, like 4.5.20 despite it having a Rust version of 1.74. + +When the resolver selects a dependency version of a package, +it does not know all the workspace members that will eventually have a transitive dependency on that version +and so it cannot take into account only the Rust versions relevant for that dependency. +The resolver has heuristics to find a "good enough" solution when workspace members have different Rust versions. +This applies even for packages in a workspace without a Rust version. + +When a workspace has members with different Rust versions, +the resolver may pick a lower dependency version than necessary. +For example, you have the following workspace members: +```toml +[package] +name = "a" +rust-version = "1.62" + +[package] +name = "b" + +[dependencies] +clap = "4.2" # resolves to 4.5.20 +``` +Though package `b` does not have a Rust version and could use a higher version like 4.5.20, +4.0.32 will be selected because of package `a`'s Rust version of 1.62. + +Or the resolver may pick too high of a version. +For example, you have the following workspace members: +```toml +[package] +name = "a" +rust-version = "1.62" + +[dependencies] +clap = "4.2" # resolves to 4.5.20 + +[package] +name = "b" + +[dependencies] +clap = "4.5" # resolves to 4.5.20 +``` +Though each package has a version requirement for `clap` that would meet its own Rust version, +because of [version unification](#version-numbers), +the resolver will need to pick one version that works in both cases and that would be a version like 4.5.20. + +[Rust version]: rust-version.md +[`resolver.incompatible-rust-versions`]: config.md#resolverincompatible-rust-versions + ### Features For the purpose of generating `Cargo.lock`, the resolver builds the dependency diff --git a/src/doc/src/reference/rust-version.md b/src/doc/src/reference/rust-version.md index 1dde3608bc2..1fd626833d0 100644 --- a/src/doc/src/reference/rust-version.md +++ b/src/doc/src/reference/rust-version.md @@ -29,6 +29,8 @@ benchmarks, etc. `cargo add` will auto-select the dependency's version requirement to be the latest version compatible with your `rust-version`. If that isn't the latest version, `cargo add` will inform users so they can make the choice on whether to keep it or update your `rust-version`. +The [resolver](resolver.md#rust-version) may take Rust version into account when picking dependencies. + Other tools may also take advantage of it, like `cargo clippy`'s [`incompatible_msrv` lint](https://rust-lang.github.io/rust-clippy/stable/index.html#/incompatible_msrv). @@ -131,6 +133,10 @@ potentially limiting access to features of the shared dependency for the workspa To allow users to patch a dependency on one of your workspace members, every package in the workspace would need to be loadable in the oldest Rust version supported by the workspace. +When using [`incompatible-rust-versions = "fallback"`](config.md#resolverincompatible-rust-versions), +the Rust version of one package can affect dependency versions selected for another package with a different Rust version. +See the [resolver](resolver.md#rust-version) chapter for more details. + ### One or More Policies One way to mitigate the downsides of supporting older Rust versions is to apply your policy to older major or minor versions of your package that you continue to support. diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 0176c39ffe2..82da1cc78ba 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -351,31 +351,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.incompatible-rust-versions` 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. -As the resolver is unable to determine which workspace members will eventually -depend on a package when it is being selected, we prioritize versions based on -how many workspace member MSRVs they are compatible with. -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 -* 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. -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 higher than any version with a compatible `rust-version` -- Specifying the version to `cargo update` with `--precise` +This was stabilized in 1.83 in [#14639](https://github.com/rust-lang/cargo/pull/14639). ### Convert `incompatible_toolchain` error into a lint diff --git a/tests/testsuite/cargo_add/rust_version_ignore/mod.rs b/tests/testsuite/cargo_add/rust_version_ignore/mod.rs index 824973464fd..39ed54242e6 100644 --- a/tests/testsuite/cargo_add/rust_version_ignore/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_ignore/mod.rs @@ -20,13 +20,11 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg("--ignore-rust-version") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .code(0) .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs b/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs index 6936642f491..09d9358c835 100644 --- a/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs @@ -23,12 +23,10 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .failure() .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rust_version_latest/mod.rs b/tests/testsuite/cargo_add/rust_version_latest/mod.rs index 8091a1c69bb..b84c9d339bf 100644 --- a/tests/testsuite/cargo_add/rust_version_latest/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_latest/mod.rs @@ -20,12 +20,10 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rust_version_older/mod.rs b/tests/testsuite/cargo_add/rust_version_older/mod.rs index 8091a1c69bb..b84c9d339bf 100644 --- a/tests/testsuite/cargo_add/rust_version_older/mod.rs +++ b/tests/testsuite/cargo_add/rust_version_older/mod.rs @@ -20,12 +20,10 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rustc_ignore/mod.rs b/tests/testsuite/cargo_add/rustc_ignore/mod.rs index 1a4719a5cbe..4eb3ca475e0 100644 --- a/tests/testsuite/cargo_add/rustc_ignore/mod.rs +++ b/tests/testsuite/cargo_add/rustc_ignore/mod.rs @@ -23,13 +23,11 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg("--ignore-rust-version") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .code(0) .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rustc_incompatible/mod.rs b/tests/testsuite/cargo_add/rustc_incompatible/mod.rs index d2bb3ebabb1..6ce13b06487 100644 --- a/tests/testsuite/cargo_add/rustc_incompatible/mod.rs +++ b/tests/testsuite/cargo_add/rustc_incompatible/mod.rs @@ -17,12 +17,10 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .failure() .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rustc_latest/mod.rs b/tests/testsuite/cargo_add/rustc_latest/mod.rs index 11a3b42167e..289bb8cecc3 100644 --- a/tests/testsuite/cargo_add/rustc_latest/mod.rs +++ b/tests/testsuite/cargo_add/rustc_latest/mod.rs @@ -23,12 +23,10 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_add/rustc_older/mod.rs b/tests/testsuite/cargo_add/rustc_older/mod.rs index 11a3b42167e..289bb8cecc3 100644 --- a/tests/testsuite/cargo_add/rustc_older/mod.rs +++ b/tests/testsuite/cargo_add/rustc_older/mod.rs @@ -23,12 +23,10 @@ fn case() { let cwd = &project_root; snapbox::cmd::Command::cargo_ui() - .arg("-Zmsrv-policy") .arg("add") .arg_line("rust-version-user") .current_dir(cwd) .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .assert() .success() .stdout_eq(str![""]) diff --git a/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg b/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg index e645347eafe..c53b850c1d2 100644 --- a/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg +++ b/tests/testsuite/cargo_generate_lockfile/help/stdout.term.svg @@ -51,7 +51,7 @@ --lockfile-path <PATH> Path to Cargo.lock (unstable) - --ignore-rust-version Ignore `rust-version` specification in packages (unstable) + --ignore-rust-version Ignore `rust-version` specification in packages --locked Assert that `Cargo.lock` will remain unchanged diff --git a/tests/testsuite/cargo_update/help/stdout.term.svg b/tests/testsuite/cargo_update/help/stdout.term.svg index 0a23a5de9e3..dd0343c9623 100644 --- a/tests/testsuite/cargo_update/help/stdout.term.svg +++ b/tests/testsuite/cargo_update/help/stdout.term.svg @@ -67,7 +67,7 @@ --lockfile-path <PATH> Path to Cargo.lock (unstable) - --ignore-rust-version Ignore `rust-version` specification in packages (unstable) + --ignore-rust-version Ignore `rust-version` specification in packages --locked Assert that `Cargo.lock` will remain unchanged diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index c36416e64af..98aae8d2593 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -218,8 +218,6 @@ fn resolve_with_rust_version() { p.cargo("generate-lockfile --ignore-rust-version") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions @@ -237,8 +235,6 @@ foo v0.0.1 ([ROOT]/foo) p.cargo("generate-lockfile") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest Rust 1.60.0 compatible versions @@ -293,8 +289,6 @@ fn resolve_with_rustc() { p.cargo("generate-lockfile --ignore-rust-version") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions @@ -314,8 +308,6 @@ foo v0.0.1 ([ROOT]/foo) p.cargo("generate-lockfile") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest Rust 1.60.0 compatible versions @@ -368,8 +360,6 @@ fn resolve_with_backtracking() { p.cargo("generate-lockfile --ignore-rust-version") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest compatible versions @@ -388,8 +378,6 @@ 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_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest Rust 1.60.0 compatible versions @@ -484,8 +472,6 @@ fn resolve_with_multiple_rust_versions() { p.cargo("generate-lockfile --ignore-rust-version") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 6 packages to latest compatible versions @@ -505,8 +491,6 @@ higher v0.0.1 ([ROOT]/foo) p.cargo("generate-lockfile") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 6 packages to latest Rust 1.50.0 compatible versions @@ -531,77 +515,6 @@ higher v0.0.1 ([ROOT]/foo) .run(); } -#[cargo_test] -fn resolve_unstable_config_on_stable() { - 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#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - 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(); - - p.cargo("generate-lockfile") - .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .with_stderr_data(str![[r#" -[WARNING] ignoring `resolver` config table without `-Zmsrv-policy` -[UPDATING] `dummy-registry` index -[LOCKING] 2 packages to latest compatible versions - -"#]]) - .run(); - p.cargo("tree") - .with_stdout_data(str![[r#" -foo v0.0.1 ([ROOT]/foo) -├── newer-and-older v1.6.0 -└── only-newer v1.6.0 - -"#]]) - .run(); - - p.cargo("generate-lockfile") - .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 -[LOCKING] 2 packages to latest compatible versions - -"#]]) - .run(); - p.cargo("tree") - .with_stdout_data(str![[r#" -foo v0.0.1 ([ROOT]/foo) -├── newer-and-older v1.6.0 -└── only-newer v1.6.0 - -"#]]) - .run(); -} - #[cargo_test(nightly, reason = "edition2024 in rustc is unstable")] fn resolve_edition2024() { Package::new("only-newer", "1.6.0") @@ -823,45 +736,6 @@ Caused by: .run(); } -#[cargo_test] -fn generate_lockfile_ignore_rust_version_is_unstable() { - Package::new("bar", "1.5.0") - .rust_version("1.55.0") - .file("src/lib.rs", "fn other_stuff() {}") - .publish(); - Package::new("bar", "1.6.0") - .rust_version("1.65.0") - .file("src/lib.rs", "fn other_stuff() {}") - .publish(); - - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - authors = [] - rust-version = "1.60.0" - [dependencies] - bar = "1.0.0" - "#, - ) - .file("src/main.rs", "fn main(){}") - .build(); - - p.cargo("generate-lockfile --ignore-rust-version") - .with_status(101) - .with_stderr_data(str![[r#" -[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel -See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. -See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag. - -"#]]) - .run(); -} - #[cargo_test] fn update_msrv_resolve() { Package::new("bar", "1.5.0") @@ -892,28 +766,15 @@ fn update_msrv_resolve() { p.cargo("update") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 1 package to latest Rust 1.60.0 compatible version [ADDING] bar v1.5.0 (available: v1.6.0, requires Rust 1.65.0) -"#]]) - .run(); - p.cargo("update --ignore-rust-version") - .with_status(101) - .with_stderr_data(str![[r#" -[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel -See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. -See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag. - "#]]) .run(); p.cargo("update --ignore-rust-version") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 1 package to latest compatible version @@ -953,8 +814,6 @@ fn update_precise_overrides_msrv_resolver() { p.cargo("update") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 1 package to latest Rust 1.60.0 compatible version @@ -964,8 +823,6 @@ fn update_precise_overrides_msrv_resolver() { .run(); p.cargo("update --precise 1.6.0 bar") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [UPDATING] bar v1.5.0 -> v1.6.0 (requires Rust 1.65.0) @@ -1010,8 +867,6 @@ fn check_msrv_resolve() { p.cargo("check --ignore-rust-version") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data( str![[r#" [UPDATING] `dummy-registry` index @@ -1040,8 +895,6 @@ foo v0.0.1 ([ROOT]/foo) std::fs::remove_file(p.root().join("Cargo.lock")).unwrap(); p.cargo("check") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 2 packages to latest Rust 1.60.0 compatible versions @@ -1086,8 +939,6 @@ fn cargo_install_ignores_msrv_config() { "CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback", ) - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [DOWNLOADING] crates ... @@ -1205,8 +1056,6 @@ fn report_rust_versions() { p.cargo("update") .env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback") - .arg("-Zmsrv-policy") - .masquerade_as_nightly_cargo(&["msrv-policy"]) .with_stderr_data(str![[r#" [UPDATING] `dummy-registry` index [LOCKING] 9 packages to latest Rust 1.60.0 compatible versions