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

Running on binary project gives wrong results [fixed] #1

Closed
TimonPost opened this issue Jul 17, 2022 · 4 comments
Closed

Running on binary project gives wrong results [fixed] #1

TimonPost opened this issue Jul 17, 2022 · 4 comments

Comments

@TimonPost
Copy link
Owner

From reddit.

Probably not a minimal example, but this fails for me:

cargo new bug
cd ./bug/
cargo add async-std
echo "fn main() { let _ = async_std::task::yield_now(); }" > ./src/main.rs
unused-features analyze
unused-features prune --input .\report.json
cargo check
@TimonPost
Copy link
Owner Author

I found the bug, it has to do with features depending on other features.
async-std contains the 'std' feature, and the std feature depends on the 'alloc' feature. In my current implementation, I do a look-up into all dependencies of 'std' and add them to the list to remove one by one. Also, I add the std feature itself. But 'std' and 'alloc' are present in the list and will both activate the task namespace. I can remove 'alloc' and see if it compiles and it will since 'std' is still present. However, in fact, we can not remove it as alloc is a required dependency.

@TimonPost
Copy link
Owner Author

TimonPost commented Jul 17, 2022

So somehow I will have to consider original features and their dependent features separately. One way to fix it is to not collect all sub-enabled features and just keep it at the root level. Then removing "std" will certainly break the compilation as it will disable all sub-features. But there might be sub-features of "std" that could be enabled individually rather than the whole set of sub-features. So we would lose some granularity/detail.

@TimonPost TimonPost changed the title Feature flag is noted as removalbe but can not be removed. Feature flag and its sub features conflict with one and another. Jul 17, 2022
@TimonPost
Copy link
Owner Author

If you're running this library on a binary rather than a library, please make sure to supply '--bin' flag. This might actually solve the issue already. Default the project only compilers libraries.

@TimonPost TimonPost changed the title Feature flag and its sub features conflict with one and another. Running on binary project gives wrong results [fixed] Jul 17, 2022
@TimonPost
Copy link
Owner Author

Flag is made default enabled in https://crates.io/crates/cargo-unused-features/0.1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant