Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,12 @@ fn build_base_args(
.env("RUSTC_BOOTSTRAP", "1");
}

if let Some(version) = unit.pkg.manifest().rust_version()
&& bcx.gctx.cli_unstable().hint_msrv
{
cmd.arg("-Z").arg(format!("hint-msrv={version}"));
}

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ unstable_cli_options!(
git: Option<GitFeatures> = ("Enable support for shallow git fetch operations"),
#[serde(deserialize_with = "deserialize_gitoxide_features")]
gitoxide: Option<GitoxideFeatures> = ("Use gitoxide for the given git interactions, or all of them if no argument is given"),
hint_msrv: bool = ("Enable passing `package.rust-version` to rustc for lints"),
host_config: bool = ("Enable the `[host]` section in the .cargo/config.toml file"),
json_target_spec: bool = ("Enable `.json` target spec files"),
min_publish_age: bool = ("Enable the `min-publish-age` configuration for dependency version age filtering"),
Expand Down Expand Up @@ -1433,6 +1434,7 @@ impl CliUnstable {
"host-config" => self.host_config = parse_empty(k, v)?,
"json-target-spec" => self.json_target_spec = parse_empty(k, v)?,
"min-publish-age" => self.min_publish_age = parse_empty(k, v)?,
"hint-msrv" => self.hint_msrv = parse_empty(k, v)?,
"next-lockfile-bump" => self.next_lockfile_bump = parse_empty(k, v)?,
"minimal-versions" => self.minimal_versions = parse_empty(k, v)?,
"msrv-policy" => self.msrv_policy = parse_empty(k, v)?,
Expand Down
15 changes: 15 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Each new feature described below should explain how to use it.
* [compile-time-deps](#compile-time-deps) --- Perma-unstable feature for rust-analyzer
* [fine-grain-locking](#fine-grain-locking) --- Use fine grain locking instead of locking the entire build cache
* [json-target-spec](#json-target-spec) --- Allows the use of `.json` custom target specs.
* [hint-msrv](#hint-msrv) --- Allows Cargo to set `-Zhint-msrv`
* rustdoc
* [rustdoc-map](#rustdoc-map) --- Provides mappings for documentation to link to external sites like [docs.rs](https://docs.rs/).
* [scrape-examples](#scrape-examples) --- Shows examples within documentation.
Expand Down Expand Up @@ -2013,6 +2014,20 @@ cargo +nightly build --target my-target.json -Z json-target-spec

This usually must be combined with [build-std](#build-std).

## hint-msrv
* Tracking Issue: [rust-lang/rust#157574](https://github.com/rust-lang/rust/issues/157574)

The -`Z hint-msrv` CLI flag enables Cargo to pass `package.rust-version` to rustc which can affect which lints are emitted.

You can set this via your global `~/.cargo/config.toml`, and nightly Cargo will
automatically use it, while stable Cargo will silently ignore the unstable
option:

```toml
[unstable]
hint-msrv = true
```

## min-publish-age

* Tracking Issue: [#17009](https://github.com/rust-lang/cargo/issues/17009)
Expand Down
66 changes: 34 additions & 32 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions tests/testsuite/hint_msrv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! Tests for `hint-msrv`

use crate::prelude::*;
use cargo_test_support::{basic_manifest, project, str};

// Test that `hint-msrv` is not available on stable
#[cargo_test]
fn hint_msrv_stable() {
let p = project().file("src/lib.rs", "").build();

p.cargo("build -Zhint-msrv").with_status(101).with_stderr_data(str![[r#"
[ERROR] the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.

"#]]).run();
}

fn msrv_manifest(name: &str, version: &str, msrv: &str) -> String {
format!(
r#"
[package]
name = "{}"
version = "{}"
authors = []
edition = "2015"
rust-version = "{}"
"#,
name, version, msrv
)
}

// Test that `hint-msrv` passes `package.rust-version`
#[cargo_test(nightly, reason = "tests nightly flag")]
fn hint_msrv() {
let p = project()
.file("src/lib.rs", "")
.file("Cargo.toml", &msrv_manifest("foo", "0.0.0", "1.78.0"))
.build();

p.cargo("build --verbose -Zhint-msrv")
.masquerade_as_nightly_cargo(&["hint-msrv"])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]-Z hint-msrv=1.78.0[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.with_status(0)
.run();

// Test that a missing package.rust-version is not an error, and does not pass a value
let p = project()
.file("src/lib.rs", "")
.file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
.build();

p.cargo("build --verbose -Zhint-msrv")
.masquerade_as_nightly_cargo(&["hint-msrv"])
.with_stderr_does_not_contain("hint-msrv")
.with_status(0)
.run();
}
1 change: 1 addition & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ mod git_shallow;
mod glob_targets;
mod global_cache_tracker;
mod help;
mod hint_msrv;
mod hints;
mod https;
mod inheritable_workspace_fields;
Expand Down