From 0daf70d816b7d2adf576a3482866dc1a32170f44 Mon Sep 17 00:00:00 2001 From: David McGillicuddy Date: Tue, 17 May 2022 19:04:48 +0100 Subject: [PATCH] Special case the string true/false error message for LTO profile arg --- src/cargo/util/toml/mod.rs | 10 ++++++++++ tests/testsuite/profiles.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c925474ad27..bb1a078b15c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -655,6 +655,16 @@ impl TomlProfile { } } + if let Some(StringOrBool::String(arg)) = &self.lto { + if arg == "true" || arg == "false" { + bail!( + "`lto` setting of string `\"{arg}\"` for `{name}` profile is not \ + a valid setting, must be a boolean (`true`/`false`) or a string \ + (`\"thin\"`/`\"fat\"`/`\"off\"`) or omitted.", + ); + } + } + Ok(()) } diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 04531e68423..17b9870bacb 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -323,6 +323,37 @@ fn profile_in_virtual_manifest_works() { .run(); } +#[cargo_test] +fn profile_lto_string_bool_dev() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + lto = "true" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .with_status(101) + .with_stderr( + "\ +error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` + +Caused by: + `lto` setting of string `\"true\"` for `dev` profile is not a valid setting, \ +must be a boolean (`true`/`false`) or a string (`\"thin\"`/`\"fat\"`/`\"off\"`) or omitted. +", + ) + .run(); +} + #[cargo_test] fn profile_panic_test_bench() { let p = project()