Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Feature Request: Add support for cargo-machete #229

Open
Elrendio opened this issue Apr 18, 2024 · 2 comments
Open

Feature Request: Add support for cargo-machete #229

Elrendio opened this issue Apr 18, 2024 · 2 comments
Assignees

Comments

@Elrendio
Copy link

Elrendio commented Apr 18, 2024

Is your feature request related to a problem? Please describe.
Yes, it's complicated to detect unused dependencies.

Describe the solution you'd like
Would you be open to adding an integration with cargo machete to highlight unused dependencies in toml files?

Detected unused dependency would be highlighted with potential actions to solve (remove dep, add cargo-machete metadata)

Describe alternatives you've considered

  • Using udeps (see FAQ)
  • Using a make target (less ergonomics)
  • Making another extension (see FAQ)

Downsides:

  • cargo machete is faillible and has known false positive that can't and won't be fixed. (EG dependencies only used in macros)
    => I think upside of compilation time of not compiling unused deps is worth it.
  • It might slow down the execution of the extension
    => I think upside of compilation time of not compiling unused deps is worth it.
  • I don't think crates currently triggers when modifying *.rs files which might become a requirement because a dependency usage can change while modifying code.

FAQ:

  • Why cargo machete and not cargo udeps?
    Speed 🚀 udeps requires compiling the crate which takes some time and can become cubersome when saving cargo.toml files.
  • Why integrate it within crates and not a custom extension?
    Unused dependencies is very small problem and I'm not sure it would be worth the investment to create a extension just for that.
  • Activate it by default or not?
    I think it should be activated by default as developers might not be aware that rustc doesn't warn on unused dependencies (specially since it does so much other things)
@duncanawoods
Copy link

duncanawoods commented Apr 22, 2024

rustc doesn't warn on unused dependencies

I agree it's surprising but they later added a lint you can enable in your Cargo.toml.

Pro

  • machete is only approximate and can be wrong
  • a lint warns you wherever/however you build

Neg

  • Bit of a pest to add to all your Cargo.tomls
  • I think it might be incorrect on benchmark dependencies (tbc)
[lints.rust]
unused_crate_dependencies = "warn"

or for workspaces:

[workspace.lints.rust]
unused_crate_dependencies = "warn"

which you can inherit in members

[lints]
workspace = true

@duncanawoods
Copy link

Oh and I see it's been implemented in a fork. Not tried it:

https://marketplace.visualstudio.com/items?itemName=citreae535.sparse-crates

@serayuzgur serayuzgur self-assigned this Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants