From d2a0d226c78b6ff8936e4f01efdf2ae8d4e3d669 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 19 Oct 2023 09:29:05 -0500 Subject: [PATCH] fix(cli): Provide next steps for bad -Z flag In #5546, they suggested we have a list of them but that would be hard to keep up and works well enough to just always mention it. Fixes #5546 --- src/cargo/core/features.rs | 5 ++++- tests/testsuite/cargo_features.rs | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 1d61db4f572d..409ad24597d5 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -1097,7 +1097,10 @@ impl CliUnstable { "script" => self.script = parse_empty(k, v)?, "target-applies-to-host" => self.target_applies_to_host = parse_empty(k, v)?, "unstable-options" => self.unstable_options = parse_empty(k, v)?, - _ => bail!("unknown `-Z` flag specified: {}", k), + _ => bail!("\ + unknown `-Z` flag specified: {k}\n\n\ + For available unstable features, see https://doc.rust-lang.org/cargo/reference/unstable.html\n\ + If you intended to use an unstable rustc feature, try setting `RUSTFLAGS=\"-Z{k}\"`"), } Ok(()) diff --git a/tests/testsuite/cargo_features.rs b/tests/testsuite/cargo_features.rs index cf7ef0190445..7663fc81fb14 100644 --- a/tests/testsuite/cargo_features.rs +++ b/tests/testsuite/cargo_features.rs @@ -594,7 +594,13 @@ fn z_flags_rejected() { p.cargo("check -Zarg") .masquerade_as_nightly_cargo(&["test-dummy-unstable"]) .with_status(101) - .with_stderr("error: unknown `-Z` flag specified: arg") + .with_stderr( + r#"error: unknown `-Z` flag specified: arg + +For available unstable features, see https://doc.rust-lang.org/cargo/reference/unstable.html +If you intended to use an unstable rustc feature, try setting `RUSTFLAGS="-Zarg"` +"#, + ) .run(); p.cargo("check -Zprint-im-a-teapot")