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

Cargo run silently passes arguments to target binary if user accidentally messes up +version order #10535

Open
orlp opened this issue Apr 2, 2022 · 4 comments
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-run S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@orlp
Copy link
Contributor

orlp commented Apr 2, 2022

Problem

I recently was (for a short while) tricked into believing my program was stuck in an infinite loop. I had ran the command

cargo run +nightly --release

It took me a while to realize that what I had written resulted in target/debug/foo.exe +nightly --release being ran, instead of running in release mode with the nightly compiler. I feel this is quite error prone, and that it's undesirable this happens entirely silently.

Proposed Solution

I propose that we display a warning when the first argument that cargo run interprets as an argument for the binary to run starts with a +. The warning can be silenced by prefixing the start of your binary argument list with -- (which you probably already should be doing anyway). So cargo run -- +nightly --release would not result in a warning, as it indicates the user really intended this behavior.

It could also simply be an error rather than a warning to start the first argument with a +, which would've probably been the better behavior from the start, but this could break existing scripts.

Notes

No response

@orlp orlp added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Apr 2, 2022
@weihanglo weihanglo added Command-run A-diagnostics Area: Error and warning messages generated by Cargo itself. labels Apr 2, 2022
@weihanglo
Copy link
Member

Ah! Seems like a common pitfall people often bump into (a similar one: #10362). We'd love to provide a way to avoid that.

Unfortunately, +toolchain is provided by a cargo proxy, which is controlled by rustup. Cargo itself knows nothing about toolchains. Emitting warnings when detecting + in arguments of the binary seems a little risky to me, because existing scripts might not expect to receive any output, though it should be rare I guess. At this time, I cannot think of a better way without breaking stuff 😞

Anyway, thanks for your report and proposal!

@orlp
Copy link
Contributor Author

orlp commented Apr 2, 2022

To be maximally conservative about breaking scripts you could only output the warning if stderr is a tty.

@bors bors closed this as completed in 642ca54 Apr 9, 2022
@ehuss
Copy link
Contributor

ehuss commented Apr 9, 2022

This was accidentally closed by a typo.

@ehuss ehuss reopened this Apr 9, 2022
@orlp
Copy link
Contributor Author

orlp commented Apr 10, 2022

This was accidentally closed by a typo.

And here I got excited when I saw the "fixed by commit" email... 😢

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. E-medium Experience: Medium and removed E-medium Experience: Medium labels May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-run S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants