Skip to content

Commit 5c45c0f

Browse files
committed
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
1 parent 4eef543 commit 5c45c0f

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

src/cargo/core/features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ unstable_cli_options!(
779779
next_lockfile_bump: bool,
780780
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
781781
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
782+
precise_pre_release: bool = ("Enable pre-release versions to be selected with `update --precise`"),
782783
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
783784
publish_timeout: bool = ("Enable the `publish.timeout` key in .cargo/config.toml file"),
784785
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
@@ -1125,6 +1126,7 @@ impl CliUnstable {
11251126
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
11261127
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
11271128
"profile-rustflags" => self.profile_rustflags = parse_empty(k, v)?,
1129+
"precise-pre-release" => self.precise_pre_release = parse_empty(k, v)?,
11281130
"trim-paths" => self.trim_paths = parse_empty(k, v)?,
11291131
"publish-timeout" => self.publish_timeout = parse_empty(k, v)?,
11301132
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,

src/doc/src/reference/unstable.md

+20
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ For the latest nightly, see the [nightly version] of this page.
7272
* [direct-minimal-versions](#direct-minimal-versions) — Forces the resolver to use the lowest compatible version instead of the highest.
7373
* [public-dependency](#public-dependency) --- Allows dependencies to be classified as either public or private.
7474
* [msrv-policy](#msrv-policy) --- MSRV-aware resolver and version selection
75+
* [precise-pre-release](#precise-pre-release) --- Allows pre-release versions to be selected with `update --precise`
7576
* Output behavior
7677
* [out-dir](#out-dir) --- Adds a directory where artifacts are copied to.
7778
* [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:
315316
The `msrv-policy` feature enables experiments in MSRV-aware policy for cargo in
316317
preparation for an upcoming RFC.
317318

319+
## precise-pre-release
320+
321+
* Tracking Issue: [#13290](https://github.com/rust-lang/rust/issues/13290)
322+
* RFC: [#3493](https://github.com/rust-lang/rfcs/pull/3493)
323+
324+
The `precise-pre-release` feature allows pre-release versions to be selected with `update --precise`
325+
even when a pre-release is not specified by a projects `Cargo.toml`.
326+
327+
Take for example this `Cargo.toml`.
328+
329+
```toml
330+
[dependencies]
331+
my-dependency = "0.1.1"
332+
```
333+
334+
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`.
335+
This is because `0.1.2-pre.0` is considered compatible with `0.1.1`.
336+
It would not be possible to upgrade to `0.2.0-pre.0` from `0.1.1` in the same way.
337+
318338
## build-std
319339
* Tracking Repository: <https://github.com/rust-lang/wg-cargo-std-aware>
320340

tests/testsuite/cargo/z_help/stdout.log

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Available unstable (nightly-only) flags:
2222
-Z mtime-on-use Configure Cargo to update the mtime of used files
2323
-Z no-index-update Do not update the registry index even if the cache is outdated
2424
-Z panic-abort-tests Enable support to run tests with -Cpanic=abort
25+
-Z precise-pre-release Enable pre-release versions to be selected with `update --precise`
2526
-Z profile-rustflags Enable the `rustflags` option in profiles in .cargo/config.toml file
2627
-Z publish-timeout Enable the `publish.timeout` key in .cargo/config.toml file
2728
-Z rustdoc-map Allow passing external documentation mappings to rustdoc

tests/testsuite/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ mod patch;
134134
mod path;
135135
mod paths;
136136
mod pkgid;
137+
mod precise_pre_release;
137138
mod proc_macro;
138139
mod profile_config;
139140
mod profile_custom;
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//! Tests for selecting pre-release versions with `update --precise`.
2+
3+
use cargo_test_support::project;
4+
5+
#[cargo_test]
6+
pub fn requires_nightly_cargo() {
7+
cargo_test_support::registry::init();
8+
9+
for version in ["0.1.1", "0.1.2-pre.0"] {
10+
cargo_test_support::registry::Package::new("my-dependency", version).publish();
11+
}
12+
13+
let p = project()
14+
.file(
15+
"Cargo.toml",
16+
r#"
17+
[package]
18+
name = "package"
19+
[dependencies]
20+
my-dependency = "0.1.1"
21+
"#,
22+
)
23+
.file("src/lib.rs", "")
24+
.build();
25+
26+
p.cargo("update -p my-dependency --precise 0.1.2-pre.0")
27+
.with_status(101)
28+
// This error is suffering from #12579 but still demonstrates that updating to
29+
// a pre-release does not work on stable
30+
.with_stderr(
31+
r#" Updating `dummy-registry` index
32+
error: failed to select a version for the requirement `my-dependency = "^0.1.1"`
33+
candidate versions found which didn't match: 0.1.2-pre.0
34+
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
35+
required by package `package v0.0.0 ([ROOT]/foo)`
36+
if you are looking for the prerelease package it needs to be specified explicitly
37+
my-dependency = { version = "0.1.2-pre.0" }
38+
perhaps a crate was updated and forgotten to be re-vendored?"#,
39+
)
40+
.run()
41+
}
42+
43+
#[cargo_test(nightly, reason = "-Zprecise_pre_release is unstable")]
44+
pub fn feature_exists() {
45+
let p = project()
46+
.file(
47+
"Cargo.toml",
48+
r#"
49+
[package]
50+
name = "package"
51+
"#,
52+
)
53+
.file("src/lib.rs", "")
54+
.build();
55+
56+
p.cargo("-Zprecise-pre-release update")
57+
.masquerade_as_nightly_cargo(&["precise-pre-release"])
58+
.with_status(0)
59+
.with_stderr("")
60+
.run()
61+
}

0 commit comments

Comments
 (0)