Skip to content

Commit 0daf70d

Browse files
committed
Special case the string true/false error message for LTO profile arg
1 parent 6d6dd9d commit 0daf70d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,16 @@ impl TomlProfile {
655655
}
656656
}
657657

658+
if let Some(StringOrBool::String(arg)) = &self.lto {
659+
if arg == "true" || arg == "false" {
660+
bail!(
661+
"`lto` setting of string `\"{arg}\"` for `{name}` profile is not \
662+
a valid setting, must be a boolean (`true`/`false`) or a string \
663+
(`\"thin\"`/`\"fat\"`/`\"off\"`) or omitted.",
664+
);
665+
}
666+
}
667+
658668
Ok(())
659669
}
660670

tests/testsuite/profiles.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,37 @@ fn profile_in_virtual_manifest_works() {
323323
.run();
324324
}
325325

326+
#[cargo_test]
327+
fn profile_lto_string_bool_dev() {
328+
let p = project()
329+
.file(
330+
"Cargo.toml",
331+
r#"
332+
[package]
333+
name = "foo"
334+
version = "0.0.1"
335+
336+
[profile.dev]
337+
lto = "true"
338+
"#,
339+
)
340+
.file("src/lib.rs", "")
341+
.build();
342+
343+
p.cargo("build")
344+
.with_status(101)
345+
.with_stderr(
346+
"\
347+
error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
348+
349+
Caused by:
350+
`lto` setting of string `\"true\"` for `dev` profile is not a valid setting, \
351+
must be a boolean (`true`/`false`) or a string (`\"thin\"`/`\"fat\"`/`\"off\"`) or omitted.
352+
",
353+
)
354+
.run();
355+
}
356+
326357
#[cargo_test]
327358
fn profile_panic_test_bench() {
328359
let p = project()

0 commit comments

Comments
 (0)