bnjbvr / cargo-machete

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

Falso positive when package name and lib name differ #111

Closed mkatychev closed 9 months ago

mkatychev commented 9 months ago

Any dependency where the package name is different from the lib name (use pkg::*;) is marked as a false positive, this seems to be consistent across the board:

[package]
name = "package"

[lib]
name = "pkg"
path = "src/lib.rs"
$ cargo machete --version
0.6.1

Example: https://github.com/maciejhirsz/tiny-bip39/blob/master/Cargo.toml#L1-L19

bnjbvr commented 9 months ago

Thanks for opening an issue. Does it work if you run cargo-machete --with-metadata? this will look for crate renamings like this one, if I remember correctly.

mkatychev commented 9 months ago

Thanks for the help @bnjbvr that does ameliorate it!

mkatychev commented 9 months ago

It would be nice if there was an option to whitelist dependencies for generated code:

[dependencies]
prost-types.workspace = true

[build-dependencies]
prost-types.workspace = true

prost-types gets flagged in this case because the generated code gets sent to OUT_DIR. I'm assuming scanning rust code generated by build.rs in OUT_DIR is a bit of a lift right now though.