Skip to content

Commit

Permalink
Introduce -Zprecise-pre-release unstable flag
Browse files Browse the repository at this point in the history
This change introduces the feature but does not yet attempt an implementation.
The actual implementation will happen in future PRs

r? @epage
  • Loading branch information
eopb committed Jan 14, 2024
1 parent 4eef543 commit 5c45c0f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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)?,
Expand Down
20 changes: 20 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: <https://github.com/rust-lang/wg-cargo-std-aware>

Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo/z_help/stdout.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
61 changes: 61 additions & 0 deletions tests/testsuite/precise_pre_release.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Tests for selecting pre-release versions with `update --precise`.

use cargo_test_support::project;

#[cargo_test]
pub 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(nightly, reason = "-Zprecise_pre_release is unstable")]
pub 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_status(0)
.with_stderr("")
.run()
}

0 comments on commit 5c45c0f

Please sign in to comment.