Repository navigation
Unused Imports
#5722
|
Hi! Is there a configuration parameter that removes unused imports? |
Answered by
wellkilo
Sep 21, 2026
Replies: 1 comment
|
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-featuresReview 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:
Neither performs unused-import analysis. Current configuration reference: If this clarifies the formatter/linter boundary, please mark the reply as accepted. |
0 replies
Answer selected by
blkmlk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-featuresReview 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|falsealphabetizes import groups.imports_granularity