diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 1cad827db1e..3cdecc02c4c 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -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(()) } diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index af8fbb8b2cf..c35b8ccb71d 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -885,6 +885,7 @@ unstable_cli_options!( git: Option = ("Enable support for shallow git fetch operations"), #[serde(deserialize_with = "deserialize_gitoxide_features")] gitoxide: Option = ("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"), @@ -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)?, diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 62ed4efcfee..06eaf2943f2 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -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. @@ -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) diff --git a/tests/testsuite/cargo/z_help/stdout.term.svg b/tests/testsuite/cargo/z_help/stdout.term.svg index c79aee4d39e..c3feb8b2e72 100644 --- a/tests/testsuite/cargo/z_help/stdout.term.svg +++ b/tests/testsuite/cargo/z_help/stdout.term.svg @@ -1,4 +1,4 @@ - +