Skip to content
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

Clarify Cargo.toml's LTO parse error message #97051

Closed
wants to merge 2 commits into from

Conversation

djmcgill
Copy link

@djmcgill djmcgill commented May 15, 2022

Make the TOML LTO parse error message a little more specific, to be clear that it accepts both boolean and string valued expressions.

Only taken a month to edit a single string 😅

Closes rust-lang/cargo#10572

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon.

Please see the contribution instructions for more information.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 15, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 15, 2022
@djmcgill
Copy link
Author

djmcgill commented May 15, 2022

Huh, I did run ./x.py test tidy --bless, one sec.
e: oh, my IDE changed it after I ran that. Cute.

@ehuss
Copy link
Contributor

ehuss commented May 15, 2022

Thanks for the PR! Unfortunately this isn't correct. The values that rustc takes are different from cargo. The error message here is for parsing rustc's CLI flag, which does not take a true or false value. We could possibly special-case this error in Cargo's profile validation. I would probably look to add it around here where the values are checked.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-12 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
status: exit status: 2
command: "make"
--- stdout -------------------------------
#Option taking a number
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C codegen-units dummy.rs 2>&1 | \
 "/checkout/src/etc/cat-and-grep.sh" 'codegen option `codegen-units` requires a number'
[[[ begin stdout ]]]
error: codegen option `codegen-units` requires a number (C codegen-units=<value>)


[[[ end stdout ]]]
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C codegen-units= dummy.rs 2>&1 | \
 "/checkout/src/etc/cat-and-grep.sh" 'incorrect value `` for codegen option `codegen-units` - a number was expected'
[[[ begin stdout ]]]
error: incorrect value `` for codegen option `codegen-units` - a number was expected


[[[ end stdout ]]]
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C codegen-units=foo dummy.rs 2>&1 | \
 "/checkout/src/etc/cat-and-grep.sh" 'incorrect value `foo` for codegen option `codegen-units` - a number was expected'
[[[ begin stdout ]]]
error: incorrect value `foo` for codegen option `codegen-units` - a number was expected


[[[ end stdout ]]]
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C codegen-units=1 dummy.rs
#Option taking a string
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C extra-filename dummy.rs 2>&1 | \
 "/checkout/src/etc/cat-and-grep.sh" 'codegen option `extra-filename` requires a string'
[[[ begin stdout ]]]
error: codegen option `extra-filename` requires a string (C extra-filename=<value>)


[[[ end stdout ]]]
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C extra-filename= dummy.rs 2>&1
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C extra-filename=foo dummy.rs 2>&1
#Option taking no argument
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/codegen-options-parsing/codegen-options-parsing  -C lto= dummy.rs 2>&1 | \
 "/checkout/src/etc/cat-and-grep.sh" 'codegen option `lto` - either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted'
[[[ begin stdout ]]]
error: incorrect value `` for codegen option `lto` - either a boolean (`true`, `false`, `yes`, `no`, `on`, `off`, etc), or a string (`"thin"`, `"fat"`), or omitted was expected


[[[ end stdout ]]]
Error: cannot match: codegen option `lto` - either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted
--- stderr -------------------------------
--- stderr -------------------------------
make: *** [Makefile:14: all] Error 1



failures:

@djmcgill
Copy link
Author

djmcgill commented May 15, 2022

Okay, I will look into that. Seems pretty straightforward. The CI failure this time is from differing compile error outputs, which makes sense, to save you a click.
I guess my obvious question is: if the rustc flags accept yes/no is there any possible reason why they shouldn't also accept true/false but also that's a bigger change and that scope is creeping away so it's not like I'm about to die on that hill (or shepherd an RFC). Thanks for looking at the PR.

@petrochenkov
Copy link
Contributor

r? @ehuss

@rust-highfive rust-highfive assigned ehuss and unassigned petrochenkov May 15, 2022
@djmcgill
Copy link
Author

Either way, this PR specifically can be closed.

@djmcgill djmcgill closed this May 15, 2022
@djmcgill djmcgill deleted the lto-error-message branch May 15, 2022 13:54
bors added a commit to rust-lang/cargo that referenced this pull request Jun 5, 2022
add validation for string "true"/"false" in lto profile

### 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?

 <!-- Demonstrate how you test this change and guide reviewers through your PR.
With a smooth review process, a pull request usually gets reviewed quicker.

If you don't know how to write and run your tests, please read the guide:
https://doc.crates.io/contrib/tests -->

Uh I've not actually tested yet that's the WIP part. But put
```
[profile.dev]
lto="false"
```
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](https://github.com/rust-lang/rust/blob/491f619f564a4ff9ae4cc837e27bb919d04c31be/compiler/rustc_session/src/options.rs#L456) 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading/confusing error message for TOML type error (for lto profile)
6 participants