Linux command
cargo-fix 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Fix all warnings
cargo fix
Fix all targets
cargo fix --all-targets
Fix with all features enabled
cargo fix --all-features
Migrate to new edition
cargo fix --edition
Fix even with compiler errors
cargo fix --broken-code
Allow dirty working directory
cargo fix --allow-dirty
Allow uncommitted changes
cargo fix --allow-staged
Fix a specific package in a workspace
cargo fix -p [package_name]
说明
cargo fix automatically applies rustc's suggested fixes to source code. Runs cargo check internally and applies machine-applicable suggestions from diagnostics.
参数
- --edition
- Apply fixes for edition migration.
- --edition-idioms
- Apply edition-specific idiom changes for the current edition.
- --broken-code
- Fix code even with existing compiler errors. Leaves broken code for manual inspection.
- --allow-dirty
- Allow fixes on a dirty working directory (including staged changes).
- --allow-staged
- Allow fixes with staged changes.
- --allow-no-vcs
- Allow fixes even if no version control system is detected.
- --all-targets
- Fix all targets (lib, bins, tests, benches, examples).
- --all-features
- Activate all available features.
- --no-default-features
- Do not activate the default feature.
- -F, --features _features_
- Space or comma-separated list of features to activate.
- --lib
- Fix library only.
- --bins
- Fix all binaries.
- --tests
- Fix all test targets.
- --benches
- Fix all benchmark targets.
- --examples
- Fix all example targets.
- -p, --package _spec_
- Fix specific packages.
- --workspace
- Fix all workspace members.
- --exclude _spec_
- Exclude specified packages (requires --workspace).
- --target _triple_
- Fix for the specified target architecture.
- -j, --jobs _N_
- Number of parallel jobs to run.
FAQ
What is the cargo-fix command used for?
cargo fix automatically applies rustc's suggested fixes to source code. Runs cargo check internally and applies machine-applicable suggestions from diagnostics.
How do I run a basic cargo-fix example?
Run `cargo fix` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --edition do in cargo-fix?
Apply fixes for edition migration.