Skip to content
Discussion options

You must be logged in to vote

No. rustfmt is intentionally a formatter, not an unused-code analyzer, so it can reorder or regroup imports but does not decide that an import is semantically unused and delete it.

Use the compiler/Clippy fix path instead:

cargo fix --allow-dirty --allow-staged
# or for the common broader pass
cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features

Review the diff afterwards, especially when conditional compilation or feature-specific imports are involved. IDE “organize imports” actions are another option, but they are separate from rustfmt.

The related rustfmt settings only control formatting:

  • reorder_imports = true|false alphabetizes import groups.
  • imports_granularity

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by blkmlk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants