Skip to content

Commit

Permalink
Auto merge of #13296 - eopb:precise-pre-release-flag, r=epage
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Jan 15, 2024
2 parents 9d3473c + c8ec94c commit 19eb0f0
Show file tree
Hide file tree
Showing 5 changed files with 84 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 @@ -780,6 +780,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 @@ -1158,6 +1159,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 @@ -316,6 +317,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 @@ -23,6 +23,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
60 changes: 60 additions & 0 deletions tests/testsuite/precise_pre_release.rs
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 19eb0f0

Please sign in to comment.