From c8ec94c765219512475a063e6af67daed9cbd3f7 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Sun, 14 Jan 2024 15:15:38 +0000 Subject: [PATCH] Introduce `-Zprecise-pre-release` unstable flag This change introduces the feature but does not yet attempt an implementation. The actual implementation will happen in future PRs r? @epage --- src/cargo/core/features.rs | 2 + src/doc/src/reference/unstable.md | 20 +++++++++ tests/testsuite/cargo/z_help/stdout.log | 1 + tests/testsuite/main.rs | 1 + tests/testsuite/precise_pre_release.rs | 60 +++++++++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 tests/testsuite/precise_pre_release.rs diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 0f6cce6e714..eb7c3de3b01 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -779,6 +779,7 @@ unstable_cli_options!( next_lockfile_bump: bool, no_index_update: bool = ("Do not update the registry index even if the cache is outdated"), panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"), + precise_pre_release: bool = ("Enable pre-release versions to be selected with `update --precise`"), profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"), publish_timeout: bool = ("Enable the `publish.timeout` key in .cargo/config.toml file"), rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"), @@ -1125,6 +1126,7 @@ impl CliUnstable { "no-index-update" => self.no_index_update = parse_empty(k, v)?, "panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?, "profile-rustflags" => self.profile_rustflags = parse_empty(k, v)?, + "precise-pre-release" => self.precise_pre_release = parse_empty(k, v)?, "trim-paths" => self.trim_paths = parse_empty(k, v)?, "publish-timeout" => self.publish_timeout = parse_empty(k, v)?, "rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?, diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 2a9916e1524..e13e0c707dc 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -72,6 +72,7 @@ For the latest nightly, see the [nightly version] of this page. * [direct-minimal-versions](#direct-minimal-versions) — Forces the resolver to use the lowest compatible version instead of the highest. * [public-dependency](#public-dependency) --- Allows dependencies to be classified as either public or private. * [msrv-policy](#msrv-policy) --- MSRV-aware resolver and version selection + * [precise-pre-release](#precise-pre-release) --- Allows pre-release versions to be selected with `update --precise` * Output behavior * [out-dir](#out-dir) --- Adds a directory where artifacts are copied to. * [Different binary name](#different-binary-name) --- Assign a name to the built binary that is separate from the crate name. @@ -315,6 +316,25 @@ Documentation updates: The `msrv-policy` feature enables experiments in MSRV-aware policy for cargo in preparation for an upcoming RFC. +## precise-pre-release + +* Tracking Issue: [#13290](https://github.com/rust-lang/rust/issues/13290) +* RFC: [#3493](https://github.com/rust-lang/rfcs/pull/3493) + +The `precise-pre-release` feature allows pre-release versions to be selected with `update --precise` +even when a pre-release is not specified by a projects `Cargo.toml`. + +Take for example this `Cargo.toml`. + +```toml +[dependencies] +my-dependency = "0.1.1" +``` + +It's possible to update `my-dependancy` to a pre-release with `update -Zprecise-pre-release -p my-dependency --precise 0.1.2-pre.0`. +This is because `0.1.2-pre.0` is considered compatible with `0.1.1`. +It would not be possible to upgrade to `0.2.0-pre.0` from `0.1.1` in the same way. + ## build-std * Tracking Repository: diff --git a/tests/testsuite/cargo/z_help/stdout.log b/tests/testsuite/cargo/z_help/stdout.log index cceeaefec06..e3a57afd2ca 100644 --- a/tests/testsuite/cargo/z_help/stdout.log +++ b/tests/testsuite/cargo/z_help/stdout.log @@ -22,6 +22,7 @@ Available unstable (nightly-only) flags: -Z mtime-on-use Configure Cargo to update the mtime of used files -Z no-index-update Do not update the registry index even if the cache is outdated -Z panic-abort-tests Enable support to run tests with -Cpanic=abort + -Z precise-pre-release Enable pre-release versions to be selected with `update --precise` -Z profile-rustflags Enable the `rustflags` option in profiles in .cargo/config.toml file -Z publish-timeout Enable the `publish.timeout` key in .cargo/config.toml file -Z rustdoc-map Allow passing external documentation mappings to rustdoc diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 1cb2d77cf1b..4643f25f834 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -134,6 +134,7 @@ mod patch; mod path; mod paths; mod pkgid; +mod precise_pre_release; mod proc_macro; mod profile_config; mod profile_custom; diff --git a/tests/testsuite/precise_pre_release.rs b/tests/testsuite/precise_pre_release.rs new file mode 100644 index 00000000000..07ee3d29d9c --- /dev/null +++ b/tests/testsuite/precise_pre_release.rs @@ -0,0 +1,60 @@ +//! Tests for selecting pre-release versions with `update --precise`. + +use cargo_test_support::project; + +#[cargo_test] +fn requires_nightly_cargo() { + cargo_test_support::registry::init(); + + for version in ["0.1.1", "0.1.2-pre.0"] { + cargo_test_support::registry::Package::new("my-dependency", version).publish(); + } + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "package" + [dependencies] + my-dependency = "0.1.1" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("update -p my-dependency --precise 0.1.2-pre.0") + .with_status(101) + // This error is suffering from #12579 but still demonstrates that updating to + // a pre-release does not work on stable + .with_stderr( + r#"[UPDATING] `dummy-registry` index +[ERROR] failed to select a version for the requirement `my-dependency = "^0.1.1"` +candidate versions found which didn't match: 0.1.2-pre.0 +location searched: `dummy-registry` index (which is replacing registry `crates-io`) +required by package `package v0.0.0 ([ROOT]/foo)` +if you are looking for the prerelease package it needs to be specified explicitly + my-dependency = { version = "0.1.2-pre.0" } +perhaps a crate was updated and forgotten to be re-vendored?"#, + ) + .run() +} + +#[cargo_test] +fn feature_exists() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "package" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("-Zprecise-pre-release update") + .masquerade_as_nightly_cargo(&["precise-pre-release"]) + .with_stderr("") + .run() +}