-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add validation for string "true"/"false" in lto profile #10676
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. Please see the contribution instructions for more information. |
src/cargo/util/toml/mod.rs
Outdated
bail!( | ||
"`lto` setting of string `\"{}\"` is not a valid setting, \ | ||
must be a boolean (`true`/`false`) or a string (`\"yes\"`/ \ | ||
`\"no\"`/`\"on\"`/`\"off\"`/`\"thin\"`/`\"fat\"`, etc) or omitted.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this does match the output of rustc if you put lto = "true"
it doesn't match the current cargo lto docs. I think it might be a good idea to either update the current cargo docs to match rustc or to only include the things that the current cargo lto docs do. I would lean towards only keeping what cargo currently does as it differs greatly from the rustc docs. I would hold off on implementing this until a maintainer chimes in but I think it would be a mistake to not have the error message here match the documentation about lto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick review, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be great to include the profile name, so the message might be like
`lto` setting of string `{arg}` for `{name}` profile is not valid. \
Must be a boolean or a string ("fat", "thin", "off").
src/cargo/util/toml/mod.rs
Outdated
if let StringOrBool::String(arg) = lto { | ||
if arg == "true" || arg == "false" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try as I might I could not get Deref
pattern matching to work here. I think because StringOrBool
doesn't implement it, so we can't use that mechanism on its contents, only match it against String
or &String
etc? And e.g. ref "true"
to force it isn't a valid pattern I discovered, that works only on bound variables not on literal patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! Could you add a unit test for the change? One similar to this is great:
cargo/tests/testsuite/profiles.rs
Lines 326 to 354 in d6cdde5
#[cargo_test] | |
fn profile_panic_test_bench() { | |
let p = project() | |
.file( | |
"Cargo.toml", | |
r#" | |
[package] | |
name = "foo" | |
version = "0.0.1" | |
[profile.test] | |
panic = "abort" | |
[profile.bench] | |
panic = "abort" | |
"#, | |
) | |
.file("src/lib.rs", "") | |
.build(); | |
p.cargo("build") | |
.with_stderr_contains( | |
"\ | |
[WARNING] `panic` setting is ignored for `bench` profile | |
[WARNING] `panic` setting is ignored for `test` profile | |
", | |
) | |
.run(); | |
} |
src/cargo/util/toml/mod.rs
Outdated
bail!( | ||
"`lto` setting of string `\"{}\"` is not a valid setting, \ | ||
must be a boolean (`true`/`false`) or a string (`\"yes\"`/ \ | ||
`\"no\"`/`\"on\"`/`\"off\"`/`\"thin\"`/`\"fat\"`, etc) or omitted.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be great to include the profile name, so the message might be like
`lto` setting of string `{arg}` for `{name}` profile is not valid. \
Must be a boolean or a string ("fat", "thin", "off").
Made the changes thanks, output currently looks like:
|
Looks nice! Could you add a unit test as I mentioned before? #10676 (review) |
Done, everything passed now. |
Thank you! |
Done, too used to autosquash ha |
Thanks! @bors r+ |
📋 Looks like this PR is still in progress, ignoring approval. Hint: Remove WIP from this PR's title when it is ready for review. |
@bors r+ |
📌 Commit 0daf70d has been approved by |
☀️ Test successful - checks-actions |
Update cargo 7 commits in 38472bc19f2f76e245eba54a6e97ee6821b3c1db..85e457e158db216a2938d51bc3b617a5a7fe6015 2022-05-31 02:03:24 +0000 to 2022-06-07 21:57:52 +0000 - Make -Z http-registry use index.crates.io when accessing crates-io (rust-lang/cargo#10725) - Respect submodule update=none strategy in .gitmodules (rust-lang/cargo#10717) - Expose rust-version through env var (rust-lang/cargo#10713) - add validation for string "true"/"false" in lto profile (rust-lang/cargo#10676) - Enhance documentation of testing (rust-lang/cargo#10726) - Clear disk space on CI. (rust-lang/cargo#10724) - Enforce to use tar v0.4.38 (rust-lang/cargo#10720)
What does this PR try to resolve?
Adds a special-cased error message for when
lto
is set to the string"true"
/"false"
which is surprisingly (I was surprised anyway) not allowed and the error message is ambiguous. The new error message makes it clear what values are accepted.Fixes #10572
How should we test and review this PR?
Uh I've not actually tested yet that's the WIP part. But put
in your TOML and run
cargo build
, check that you get the new error message and that it makes sense and is helpful.Additional information
It's worth noting that as per rust-lang/rust#97051 this doesn't fix the real problem here IMO which is that rust's
opt_parse_bool
cli parsing doesn't accept true/false which certainly seems an ad-hoc historical choice to me on first glance but also it's a much bigger change to change those semantics than this error message.