Skip to content

Commit 19eb0f0

Browse files
committed
Auto merge of #13296 - eopb:precise-pre-release-flag, r=epage
Introduce `-Zprecise-pre-release` unstable flag Tracking Issue: [#13290](#13290) This change introduces the feature but does not yet attempt an implementation. The actual implementation will happen in future PRs. r? `@epage`
2 parents 9d3473c + c8ec94c commit 19eb0f0

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

src/cargo/core/features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ unstable_cli_options!(
780780
next_lockfile_bump: bool,
781781
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
782782
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
783+
precise_pre_release: bool = ("Enable pre-release versions to be selected with `update --precise`"),
783784
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
784785
publish_timeout: bool = ("Enable the `publish.timeout` key in .cargo/config.toml file"),
785786
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
@@ -1158,6 +1159,7 @@ impl CliUnstable {
11581159
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
11591160
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
11601161
"profile-rustflags" => self.profile_rustflags = parse_empty(k, v)?,
1162+
"precise-pre-release" => self.precise_pre_release = parse_empty(k, v)?,
11611163
"trim-paths" => self.trim_paths = parse_empty(k, v)?,
11621164
"publish-timeout" => self.publish_timeout = parse_empty(k, v)?,
11631165
"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.
@@ -316,6 +317,25 @@ Documentation updates:
316317
The `msrv-policy` feature enables experiments in MSRV-aware policy for cargo in
317318
preparation for an upcoming RFC.
318319

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

tests/testsuite/cargo/z_help/stdout.log

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Available unstable (nightly-only) flags:
2323
-Z mtime-on-use Configure Cargo to update the mtime of used files
2424
-Z no-index-update Do not update the registry index even if the cache is outdated
2525
-Z panic-abort-tests Enable support to run tests with -Cpanic=abort
26+
-Z precise-pre-release Enable pre-release versions to be selected with `update --precise`
2627
-Z profile-rustflags Enable the `rustflags` option in profiles in .cargo/config.toml file
2728
-Z publish-timeout Enable the `publish.timeout` key in .cargo/config.toml file
2829
-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;
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! Tests for selecting pre-release versions with `update --precise`.
2+
3+
use cargo_test_support::project;
4+
5+
#[cargo_test]
6+
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]
44+
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_stderr("")
59+
.run()
60+
}

0 commit comments

Comments
 (0)