-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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' miscounts binaries due to features, can even panic #3867
Comments
Just compiling first and do any checks (e.g. "there is exactly one binary") afterwards doesn't work, as this would be a performance bug (unnecessarily slow) and many tests check for stdout, which would "suddenly" also contain compilation. Refactoring Improving |
cc @jbendig |
Thanks for reporting this issue! This is definitely wrong and I can reproduce it. I'll work on fixing it. |
Awesome, thank you! Please have a look at some thoughts I gave about this, and why it looks to me like that this will need a refactor of |
@BenWiederhake Thanks! I'll take a look. |
Fix `cargo run` panic when required-features not satisfied This PR fixes #3867 which is made up of two parts. The first part involves `cargo run` triggering an assertion after compiling. This is triggered by the single binary selected for compilation being filtered out when required-features is specified and said features are not enabled. The cleanest approach to me involves just sticking a flag into `CompileFilter::Everything`. The flag then triggers the already existing error message when required-features is not satisfied. I think this works best because it localizes what is really a `cargo run` quirk without requiring any boilerplate or duplicate code. The second part shows `cargo run` bailing when two binaries exist, both with required-features, but only one is resolved to be compiled due to default features. I feel like the current approach is correct because it's consistent with what normally happens when there are multiple binaries. I'm open to changing this, but for now, I've added a test to enforce this behavior. cc @BenWiederhake: I took a quick peek at your branch to fix #3112 and I noticed that it probably won't merge cleanly with this PR. Just an FYI in case it makes sense to have this merged.
Discovered while working indirectly on
cargo_run.rs
.Example 1: One binary in the eyes of
cargo_run
(wrong), butcargo_compile
produces no binaries (correct), makingcargo_run
panic:Behavior:
Example 2: Two binaries in the eyes of
cargo_run
(wrong), butcargo_compile
produces only one binary (correct), makingcargo_run
bail unnecessarily:Behavior:
This might also be helpful for users having issue #2200.
The text was updated successfully, but these errors were encountered: