From 51aeeb01ff7b616331809a1b7218f06c4a87ba86 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 1d61db4f572..224885c955d 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/nightly/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 cf7ef019044..d319ed686c3 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/nightly/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")