bnjbvr / cargo-machete

Remove unused Rust dependencies with this one weird trick!
MIT License
784 stars 28 forks source link

feat: remove features when removing dependencies #113

Open njelich opened 7 months ago

njelich commented 7 months ago

When removing dependencies using the --fix flag, the features for those dependencies are not removed. This adds support for that.

I tested it manually, but tests should probably be written to make sure it works generally. From what I can see there are currently no tests for the --fix functionality anyway.

njelich commented 7 months ago

@bnjbvr Pending review

bnjbvr commented 7 months ago

Hi, as I'm working on my spare time on this project, I might not be very reactive for reviews and all of that.

That being said: how does this work? How can you guess the feature's name? (are you assuming the feature's named after the dependency?) Not sure how prevalent that usage is, so unclear whether we should do that automatically...

njelich commented 7 months ago

@bnjbvr I added a test case so you can see what it does. You can also add more autofix tests using the same setup.

njelich commented 7 months ago

In short, for a Cargo.toml with the unused log dependency:

[dependencies]
log = "0.4.14"

[features]
default = ["std"]
std = ["log/std", "other"]
other = []

It sees the log dependency is unused, and that the std feature on the log dependency is used with log/std. When removing log, it also removes the log/std feature.

[dependencies]

[features]
default = ["std"]
std = [ "other"]
other = []
njelich commented 7 months ago

@bnjbvr Have you had a chance to take a look at this?

bnjbvr commented 2 months ago

Getting back to this: any idea why the CI doesn't even show up? There's no job and no way for me to approve the run or not 🤔

njelich commented 2 months ago

Will check later today