diff --git a/CHANGELOG.md b/CHANGELOG.md index fce54d5df0f..a3d9e80c594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Added +- Added support for the [`rust-version`](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field) + field in a crate's metadata and the `--ignore-rust-version` command line option. - Build scripts can now pass additional linker arguments for binaries or all linkable targets. [docs](https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#outputs-of-the-build-script) [#9557](https://github.com/rust-lang/cargo/pull/9557) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 3011e65567f..e338a66acea 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -166,8 +166,7 @@ impl Edition { match self { Edition2015 => None, Edition2018 => Some(semver::Version::new(1, 31, 0)), - // FIXME: This will likely be 1.56, update when that seems more likely. - Edition2021 => Some(semver::Version::new(1, 62, 0)), + Edition2021 => Some(semver::Version::new(1, 56, 0)), } } @@ -396,7 +395,7 @@ features! { (unstable, strip, "", "reference/unstable.html#profile-strip-option"), // Specifying a minimal 'rust-version' attribute for crates - (unstable, rust_version, "", "reference/unstable.html#rust-version"), + (stable, rust_version, "1.56", "reference/manifest.html#the-rust-version-field"), // Support for 2021 edition. (unstable, edition2021, "", "reference/unstable.html#edition-2021"), diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 3253cfb1008..61f73ffae1c 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -218,7 +218,7 @@ pub trait AppExt: Sized { fn arg_ignore_rust_version(self) -> Self { self._arg(opt( "ignore-rust-version", - "Ignore `rust-version` specification in packages (unstable)", + "Ignore `rust-version` specification in packages", )) } @@ -533,12 +533,6 @@ pub trait ArgMatchesExt { honor_rust_version: !self._is_present("ignore-rust-version"), }; - if !opts.honor_rust_version { - config - .cli_unstable() - .fail_if_stable_opt("--ignore-rust-version", 8072)?; - } - if let Some(ws) = workspace { self.check_optional_opts(ws, &opts)?; } else if self.is_present_with_zero_values("package") { diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 6a928c4b0ce..e32160ea2b3 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1122,46 +1122,25 @@ impl TomlManifest { } let rust_version = if let Some(rust_version) = &project.rust_version { - if features.require(Feature::rust_version()).is_err() { - let mut msg = - "`rust-version` is not supported on this version of Cargo and will be ignored" - .to_string(); - if config.nightly_features_allowed { - msg.push_str( - "\n\n\ - consider adding `cargo-features = [\"rust-version\"]` to the manifest", - ); - } else { - msg.push_str( - "\n\n\ - this Cargo does not support nightly features, but if you\n\ - switch to nightly channel you can add\n\ - `cargo-features = [\"rust-version\"]` to enable this feature", - ); - } - warnings.push(msg); - None - } else { - let req = match semver::VersionReq::parse(rust_version) { - // Exclude semver operators like `^` and pre-release identifiers - Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req, - _ => bail!("`rust-version` must be a value like \"1.32\""), - }; - if let Some(first_version) = edition.first_version() { - let unsupported = - semver::Version::new(first_version.major, first_version.minor - 1, 9999); - if req.matches(&unsupported) { - bail!( - "rust-version {} is older than first version ({}) required by \ - the specified edition ({})", - rust_version, - first_version, - edition, - ) - } + let req = match semver::VersionReq::parse(rust_version) { + // Exclude semver operators like `^` and pre-release identifiers + Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req, + _ => bail!("`rust-version` must be a value like \"1.32\""), + }; + if let Some(first_version) = edition.first_version() { + let unsupported = + semver::Version::new(first_version.major, first_version.minor - 1, 9999); + if req.matches(&unsupported) { + bail!( + "rust-version {} is older than first version ({}) required by \ + the specified edition ({})", + rust_version, + first_version, + edition, + ) } - Some(rust_version.clone()) } + Some(rust_version.clone()) } else { None }; diff --git a/src/doc/man/cargo-bench.md b/src/doc/man/cargo-bench.md index beab222b53f..9c62c2d1e83 100644 --- a/src/doc/man/cargo-bench.md +++ b/src/doc/man/cargo-bench.md @@ -83,6 +83,8 @@ target. {{> options-target-triple }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-build.md b/src/doc/man/cargo-build.md index d7f04479a1e..ceca80d2929 100644 --- a/src/doc/man/cargo-build.md +++ b/src/doc/man/cargo-build.md @@ -35,6 +35,8 @@ they have `required-features` that are missing. {{> options-release }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-check.md b/src/doc/man/cargo-check.md index 316ccd9f1b4..c31411a9183 100644 --- a/src/doc/man/cargo-check.md +++ b/src/doc/man/cargo-check.md @@ -42,6 +42,8 @@ they have `required-features` that are missing. {{> options-profile }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-doc.md b/src/doc/man/cargo-doc.md index 5d87c72e640..d7c3dc7299c 100644 --- a/src/doc/man/cargo-doc.md +++ b/src/doc/man/cargo-doc.md @@ -64,6 +64,8 @@ flag and will always document the given target. {{> options-release }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-fix.md b/src/doc/man/cargo-fix.md index ab1e24e4759..de8a39a5d0d 100644 --- a/src/doc/man/cargo-fix.md +++ b/src/doc/man/cargo-fix.md @@ -122,6 +122,8 @@ When no target selection options are given, `cargo fix` will fix all targets {{> options-profile }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-run.md b/src/doc/man/cargo-run.md index bd545613c90..7ba63c91eaf 100644 --- a/src/doc/man/cargo-run.md +++ b/src/doc/man/cargo-run.md @@ -50,6 +50,8 @@ Run the specified example. {{> options-release }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-rustc.md b/src/doc/man/cargo-rustc.md index c7f74573bee..178580a2edb 100644 --- a/src/doc/man/cargo-rustc.md +++ b/src/doc/man/cargo-rustc.md @@ -47,6 +47,8 @@ binary and library targets of the selected package. {{> options-release }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-rustdoc.md b/src/doc/man/cargo-rustdoc.md index af5d6906ae2..40aaff20018 100644 --- a/src/doc/man/cargo-rustdoc.md +++ b/src/doc/man/cargo-rustdoc.md @@ -62,6 +62,8 @@ if its name is the same as the lib target. Binaries are skipped if they have {{> options-release }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/cargo-test.md b/src/doc/man/cargo-test.md index e4bd1ce2ee7..eb352e46e7b 100644 --- a/src/doc/man/cargo-test.md +++ b/src/doc/man/cargo-test.md @@ -102,6 +102,8 @@ target options. {{> options-release }} +{{> options-ignore-rust-version }} + {{/options}} ### Output Options diff --git a/src/doc/man/generated_txt/cargo-bench.txt b/src/doc/man/generated_txt/cargo-bench.txt index 020360f6cee..5a933063709 100644 --- a/src/doc/man/generated_txt/cargo-bench.txt +++ b/src/doc/man/generated_txt/cargo-bench.txt @@ -202,6 +202,11 @@ OPTIONS documentation for more details. + --ignore-rust-version + Benchmark the target even if the selected Rust compiler is older + than the required Rust version as configured in the project's + rust-version field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-build.txt b/src/doc/man/generated_txt/cargo-build.txt index cb3ccb05655..4b321d9f7cb 100644 --- a/src/doc/man/generated_txt/cargo-build.txt +++ b/src/doc/man/generated_txt/cargo-build.txt @@ -146,6 +146,11 @@ OPTIONS Build optimized artifacts with the release profile. See the PROFILES section for details on how this affects profile selection. + --ignore-rust-version + Build the target even if the selected Rust compiler is older than + the required Rust version as configured in the project's + rust-version field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-check.txt b/src/doc/man/generated_txt/cargo-check.txt index 430118c31aa..ce8281c6a27 100644 --- a/src/doc/man/generated_txt/cargo-check.txt +++ b/src/doc/man/generated_txt/cargo-check.txt @@ -158,6 +158,11 @@ OPTIONS have it check unit tests which are usually excluded via the cfg attribute. This does not change the actual profile used. + --ignore-rust-version + Check the target even if the selected Rust compiler is older than + the required Rust version as configured in the project's + rust-version field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-doc.txt b/src/doc/man/generated_txt/cargo-doc.txt index a7b160b54b1..2b34fb93fc7 100644 --- a/src/doc/man/generated_txt/cargo-doc.txt +++ b/src/doc/man/generated_txt/cargo-doc.txt @@ -123,6 +123,11 @@ OPTIONS Document optimized artifacts with the release profile. See the PROFILES section for details on how this affects profile selection. + --ignore-rust-version + Document the target even if the selected Rust compiler is older than + the required Rust version as configured in the project's + rust-version field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-fix.txt b/src/doc/man/generated_txt/cargo-fix.txt index c2b3aa5300d..450023a7241 100644 --- a/src/doc/man/generated_txt/cargo-fix.txt +++ b/src/doc/man/generated_txt/cargo-fix.txt @@ -231,6 +231,11 @@ OPTIONS it fix unit tests which are usually excluded via the cfg attribute. This does not change the actual profile used. + --ignore-rust-version + Fix the target even if the selected Rust compiler is older than the + required Rust version as configured in the project's rust-version + field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-run.txt b/src/doc/man/generated_txt/cargo-run.txt index a27d51fceb5..918f161b5d2 100644 --- a/src/doc/man/generated_txt/cargo-run.txt +++ b/src/doc/man/generated_txt/cargo-run.txt @@ -75,6 +75,11 @@ OPTIONS Run optimized artifacts with the release profile. See the PROFILES section for details on how this affects profile selection. + --ignore-rust-version + Run the target even if the selected Rust compiler is older than the + required Rust version as configured in the project's rust-version + field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-rustc.txt b/src/doc/man/generated_txt/cargo-rustc.txt index 92a77d5cebe..d8d18ccaedf 100644 --- a/src/doc/man/generated_txt/cargo-rustc.txt +++ b/src/doc/man/generated_txt/cargo-rustc.txt @@ -137,6 +137,11 @@ OPTIONS Build optimized artifacts with the release profile. See the PROFILES section for details on how this affects profile selection. + --ignore-rust-version + Build the target even if the selected Rust compiler is older than + the required Rust version as configured in the project's + rust-version field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-rustdoc.txt b/src/doc/man/generated_txt/cargo-rustdoc.txt index d6161e79e2b..628bbcfe595 100644 --- a/src/doc/man/generated_txt/cargo-rustdoc.txt +++ b/src/doc/man/generated_txt/cargo-rustdoc.txt @@ -146,6 +146,11 @@ OPTIONS Document optimized artifacts with the release profile. See the PROFILES section for details on how this affects profile selection. + --ignore-rust-version + Document the target even if the selected Rust compiler is older than + the required Rust version as configured in the project's + rust-version field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/generated_txt/cargo-test.txt b/src/doc/man/generated_txt/cargo-test.txt index e4e6f993644..e554e938c38 100644 --- a/src/doc/man/generated_txt/cargo-test.txt +++ b/src/doc/man/generated_txt/cargo-test.txt @@ -223,6 +223,11 @@ OPTIONS Test optimized artifacts with the release profile. See the PROFILES section for details on how this affects profile selection. + --ignore-rust-version + Test the target even if the selected Rust compiler is older than the + required Rust version as configured in the project's rust-version + field. + Output Options --target-dir directory Directory for all generated artifacts and intermediate files. May diff --git a/src/doc/man/includes/options-ignore-rust-version.md b/src/doc/man/includes/options-ignore-rust-version.md new file mode 100644 index 00000000000..a151534e944 --- /dev/null +++ b/src/doc/man/includes/options-ignore-rust-version.md @@ -0,0 +1,4 @@ +{{#option "`--ignore-rust-version`"}} +{{actionverb}} the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's `rust-version` field. +{{/option}} diff --git a/src/doc/src/commands/cargo-bench.md b/src/doc/src/commands/cargo-bench.md index b3ecc76a15c..ce58f230758 100644 --- a/src/doc/src/commands/cargo-bench.md +++ b/src/doc/src/commands/cargo-bench.md @@ -245,6 +245,12 @@ target artifacts are placed in a separate directory. See the +
--ignore-rust-version
+
Benchmark the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-build.md b/src/doc/src/commands/cargo-build.md index 8efbd73fb95..fb372dc0007 100644 --- a/src/doc/src/commands/cargo-build.md +++ b/src/doc/src/commands/cargo-build.md @@ -188,6 +188,12 @@ selection. +
--ignore-rust-version
+
Build the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-check.md b/src/doc/src/commands/cargo-check.md index 421e5677cf1..28340b26ac9 100644 --- a/src/doc/src/commands/cargo-check.md +++ b/src/doc/src/commands/cargo-check.md @@ -202,6 +202,12 @@ used. +
--ignore-rust-version
+
Check the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-doc.md b/src/doc/src/commands/cargo-doc.md index b96e7e95378..6f8255ca3ab 100644 --- a/src/doc/src/commands/cargo-doc.md +++ b/src/doc/src/commands/cargo-doc.md @@ -161,6 +161,12 @@ selection. +
--ignore-rust-version
+
Document the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-fix.md b/src/doc/src/commands/cargo-fix.md index 0d8c9143369..534520188d3 100644 --- a/src/doc/src/commands/cargo-fix.md +++ b/src/doc/src/commands/cargo-fix.md @@ -282,6 +282,12 @@ used. +
--ignore-rust-version
+
Fix the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-run.md b/src/doc/src/commands/cargo-run.md index 938d8ef4dac..d7cf9ec5fb9 100644 --- a/src/doc/src/commands/cargo-run.md +++ b/src/doc/src/commands/cargo-run.md @@ -106,6 +106,12 @@ selection. +
--ignore-rust-version
+
Run the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-rustc.md b/src/doc/src/commands/cargo-rustc.md index 002ef1ac550..65dbeee3fff 100644 --- a/src/doc/src/commands/cargo-rustc.md +++ b/src/doc/src/commands/cargo-rustc.md @@ -175,6 +175,12 @@ selection. +
--ignore-rust-version
+
Build the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-rustdoc.md b/src/doc/src/commands/cargo-rustdoc.md index b0b31cec6cc..96de095f821 100644 --- a/src/doc/src/commands/cargo-rustdoc.md +++ b/src/doc/src/commands/cargo-rustdoc.md @@ -190,6 +190,12 @@ selection. +
--ignore-rust-version
+
Document the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/commands/cargo-test.md b/src/doc/src/commands/cargo-test.md index d7872462aac..e2daf71f681 100644 --- a/src/doc/src/commands/cargo-test.md +++ b/src/doc/src/commands/cargo-test.md @@ -269,6 +269,12 @@ selection. +
--ignore-rust-version
+
Test the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's rust-version field.
+ + + ### Output Options diff --git a/src/doc/src/reference/manifest.md b/src/doc/src/reference/manifest.md index 337169a2de7..0a3566b5062 100644 --- a/src/doc/src/reference/manifest.md +++ b/src/doc/src/reference/manifest.md @@ -9,6 +9,7 @@ in the [TOML] format. Every manifest file consists of the following sections: * [`version`](#the-version-field) — The version of the package. * [`authors`](#the-authors-field) — The authors of the package. * [`edition`](#the-edition-field) — The Rust edition. + * [`rust-version`](#the-rust-version-field) — The minimal supported Rust version. * [`description`](#the-description-field) — A description of the package. * [`documentation`](#the-documentation-field) — URL of the package documentation. * [`readme`](#the-readme-field) — Path to the package's README file. @@ -144,6 +145,33 @@ assumed for backwards compatibility. Note that all manifests created with [`cargo new`] will not use this historical fallback because they will have `edition` explicitly specified to a newer value. +#### The `rust-version` field + +The `rust-version` field is an optional key that tells cargo what version of the +Rust language and compiler your package can be compiled with. If the currently +selected version of the Rust compiler is older than the stated version, cargo +will exit with an error, telling the user what version is required. + +The first version of Cargo that supports this field was released with Rust 1.56.0. +In older releases, the field will be ignored, and Cargo will display a warning. + +```toml +[package] +# ... +rust-version = "1.56" +``` + +The Rust version must be a bare version number with two or three components; it +cannot include semver operators or pre-release identifiers. Compiler pre-release +identifiers such as -nightly will be ignored while checking the Rust version. +The `rust-version` must be equal to or newer than the version that first +introduced the configured `edition`. + +The `rust-version` may be ignored using the `--ignore-rust-version` option. + +Setting the `rust-version` key in `[package]` will affect all targets/crates in +the package, including test suites, benchmarks, binaries, examples, etc. + #### The `description` field The description is a short blurb about the package. [crates.io] will display diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 1feff2dd8b7..0eafbd0e5fe 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -89,7 +89,6 @@ Each new feature described below should explain how to use it. * [Custom named profiles](#custom-named-profiles) — Adds custom named profiles in addition to the standard names. * [Profile `strip` option](#profile-strip-option) — Forces the removal of debug information and symbols from executables. * [per-package-target](#per-package-target) — Sets the `--target` to use for each individual package. - * [rust-version](#rust-version) — Allows to declare the minimum supported Rust version. * [Edition 2021](#edition-2021) — Adds support for the 2021 Edition. * Information and metadata * [Build-plan](#build-plan) — Emits JSON information on which commands will be run. @@ -1170,25 +1169,6 @@ cargo logout -Z credential-process [crates.io]: https://crates.io/ [config file]: config.md -### rust-version -* RFC: [#2495](https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md) -* rustc Tracking Issue: [#65262](https://github.com/rust-lang/rust/issues/65262) - -The `-Z rust-version` flag enables the reading of the `rust-version` field in the -Cargo manifest `package` section. This can be used by a package to state a minimal -version of the compiler required to build the package. An error is generated if -the version of rustc is older than the stated `rust-version`. The -`--ignore-rust-version` flag can be used to override the check. - -```toml -cargo-features = ["rust-version"] - -[package] -name = "mypackage" -version = "0.0.1" -rust-version = "1.42" -``` - ### edition 2021 * Tracking Issue: [rust-lang/rust#85811](https://github.com/rust-lang/rust/issues/85811) @@ -1420,3 +1400,9 @@ The `configurable-env` feature to specify environment variables in Cargo configuration has been stabilized in the 1.56 release. See the [config documentation](config.html#env) for more information about configuring environment variables. + +### rust-version + +The `rust-version` field in `Cargo.toml` has been stabilized in the 1.56 release. +See the [rust-version field](manifest.html#the-rust-version-field) for more +information on using the `rust-version` field and the `--ignore-rust-version` option. diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1 index 5b7be795b11..a8239d002d9 100644 --- a/src/etc/man/cargo-bench.1 +++ b/src/etc/man/cargo-bench.1 @@ -250,6 +250,12 @@ Note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the \fIbuild cache\fR documentation for more details. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Benchmark the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1 index f847c84385a..4eaea1bc5a7 100644 --- a/src/etc/man/cargo-build.1 +++ b/src/etc/man/cargo-build.1 @@ -175,6 +175,12 @@ Build optimized artifacts with the \fBrelease\fR profile. See the PROFILES section for details on how this affects profile selection. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Build the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1 index 453ca7fd785..7c6b2ea17d2 100644 --- a/src/etc/man/cargo-check.1 +++ b/src/etc/man/cargo-check.1 @@ -189,6 +189,12 @@ This is useful to have it check unit tests which are usually excluded via the \fBcfg\fR attribute. This does not change the actual profile used. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Check the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1 index 46bb4dca3bd..3d783b7547b 100644 --- a/src/etc/man/cargo-doc.1 +++ b/src/etc/man/cargo-doc.1 @@ -142,6 +142,12 @@ Document optimized artifacts with the \fBrelease\fR profile. See the PROFILES section for details on how this affects profile selection. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Document the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1 index 7b3caa770ec..57eb1da015f 100644 --- a/src/etc/man/cargo-fix.1 +++ b/src/etc/man/cargo-fix.1 @@ -284,6 +284,12 @@ This is useful to have it fix unit tests which are usually excluded via the \fBcfg\fR attribute. This does not change the actual profile used. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Fix the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-run.1 b/src/etc/man/cargo-run.1 index 6dee945b170..c4ff6e444bf 100644 --- a/src/etc/man/cargo-run.1 +++ b/src/etc/man/cargo-run.1 @@ -86,6 +86,12 @@ Run optimized artifacts with the \fBrelease\fR profile. See the PROFILES section for details on how this affects profile selection. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Run the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-rustc.1 b/src/etc/man/cargo-rustc.1 index 88d8d7d6ea4..5a69821c6e1 100644 --- a/src/etc/man/cargo-rustc.1 +++ b/src/etc/man/cargo-rustc.1 @@ -161,6 +161,12 @@ Build optimized artifacts with the \fBrelease\fR profile. See the PROFILES section for details on how this affects profile selection. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Build the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1 index 7ff1b638da1..2a9af8cf6b1 100644 --- a/src/etc/man/cargo-rustdoc.1 +++ b/src/etc/man/cargo-rustdoc.1 @@ -172,6 +172,12 @@ Document optimized artifacts with the \fBrelease\fR profile. See the PROFILES section for details on how this affects profile selection. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Document the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1 index 586f5ead916..bafeb08662e 100644 --- a/src/etc/man/cargo-test.1 +++ b/src/etc/man/cargo-test.1 @@ -272,6 +272,12 @@ Test optimized artifacts with the \fBrelease\fR profile. See the PROFILES section for details on how this affects profile selection. .RE +.sp +\fB\-\-ignore\-rust\-version\fR +.RS 4 +Test the target even if the selected Rust compiler is older than the +required Rust version as configured in the project's \fBrust\-version\fR field. +.RE .SS "Output Options" .sp \fB\-\-target\-dir\fR \fIdirectory\fR diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs index 7792cbee17b..6f849141ff6 100644 --- a/tests/testsuite/rust_version.rs +++ b/tests/testsuite/rust_version.rs @@ -2,58 +2,12 @@ use cargo_test_support::{project, registry::Package}; -#[cargo_test] -fn rust_version_gated() { - project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - rust-version = "1.9999" - "#, - ) - .file("src/lib.rs", "") - .build() - .cargo("build") - .masquerade_as_nightly_cargo() - .with_stderr_contains( - "warning: `rust-version` is not supported on this version of Cargo and will be ignored\ - \n\nconsider adding `cargo-features = [\"rust-version\"]` to the manifest", - ) - .run(); - - project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - rust-version = "1.9999" - "#, - ) - .file("src/lib.rs", "") - .build() - .cargo("build") - .with_stderr_contains( - "warning: `rust-version` is not supported on this version of Cargo and will be ignored\ - \n\nthis Cargo does not support nightly features, but if you\n\ - switch to nightly channel you can add\n\ - `cargo-features = [\"rust-version\"]` to enable this feature", - ) - .run(); -} - #[cargo_test] fn rust_version_satisfied() { let p = project() .file( "Cargo.toml", r#" - cargo-features = ["rust-version"] - [project] name = "foo" version = "0.0.1" @@ -66,10 +20,8 @@ fn rust_version_satisfied() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("build").masquerade_as_nightly_cargo().run(); - p.cargo("build --ignore-rust-version -Zunstable-options") - .masquerade_as_nightly_cargo() - .run(); + p.cargo("build").run(); + p.cargo("build --ignore-rust-version").run(); } #[cargo_test] @@ -78,8 +30,6 @@ fn rust_version_bad_caret() { .file( "Cargo.toml", r#" - cargo-features = ["rust-version"] - [project] name = "foo" version = "0.0.1" @@ -92,7 +42,6 @@ fn rust_version_bad_caret() { .file("src/main.rs", "fn main() {}") .build() .cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "error: failed to parse manifest at `[..]`\n\n\ @@ -107,8 +56,6 @@ fn rust_version_bad_pre_release() { .file( "Cargo.toml", r#" - cargo-features = ["rust-version"] - [project] name = "foo" version = "0.0.1" @@ -121,7 +68,6 @@ fn rust_version_bad_pre_release() { .file("src/main.rs", "fn main() {}") .build() .cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "error: failed to parse manifest at `[..]`\n\n\ @@ -136,8 +82,6 @@ fn rust_version_bad_nonsense() { .file( "Cargo.toml", r#" - cargo-features = ["rust-version"] - [project] name = "foo" version = "0.0.1" @@ -150,7 +94,6 @@ fn rust_version_bad_nonsense() { .file("src/main.rs", "fn main() {}") .build() .cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "error: failed to parse manifest at `[..]`\n\n\ @@ -165,8 +108,6 @@ fn rust_version_too_high() { .file( "Cargo.toml", r#" - cargo-features = ["rust-version"] - [project] name = "foo" version = "0.0.1" @@ -180,22 +121,18 @@ fn rust_version_too_high() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( "error: package `foo v0.0.1 ([..])` cannot be built because it requires \ rustc 1.9876.0 or newer, while the currently active rustc version is [..]", ) .run(); - p.cargo("build --ignore-rust-version -Zunstable-options") - .masquerade_as_nightly_cargo() - .run(); + p.cargo("build --ignore-rust-version").run(); } #[cargo_test] fn rust_version_dependency_fails() { Package::new("bar", "0.0.1") - .cargo_feature("rust-version") .rust_version("1.2345.0") .file("src/lib.rs", "fn other_stuff() {}") .publish(); @@ -216,7 +153,6 @@ fn rust_version_dependency_fails() { .build(); p.cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr( " Updating `[..]` index\n \ @@ -226,9 +162,7 @@ fn rust_version_dependency_fails() { rustc 1.2345.0 or newer, while the currently active rustc version is [..]", ) .run(); - p.cargo("build --ignore-rust-version -Zunstable-options") - .masquerade_as_nightly_cargo() - .run(); + p.cargo("build --ignore-rust-version").run(); } #[cargo_test] @@ -237,8 +171,6 @@ fn rust_version_older_than_edition() { .file( "Cargo.toml", r#" - cargo-features = ["rust-version"] - [project] name = "foo" version = "0.0.1" @@ -252,7 +184,6 @@ fn rust_version_older_than_edition() { .file("src/main.rs", "fn main() {}") .build() .cargo("build") - .masquerade_as_nightly_cargo() .with_status(101) .with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)", )