LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

cargo-fix

Automatically fix compiler warnings in Rust code

TLDR

Fix all warnings
$ cargo fix
copy
Fix all targets
$ cargo fix --all-targets
copy
Fix with all features enabled
$ cargo fix --all-features
copy
Migrate to new edition
$ cargo fix --edition
copy
Fix even with compiler errors
$ cargo fix --broken-code
copy
Allow dirty working directory
$ cargo fix --allow-dirty
copy
Allow uncommitted changes
$ cargo fix --allow-staged
copy
Fix a specific package in a workspace
$ cargo fix -p [package_name]
copy

SYNOPSIS

cargo fix [options]

DESCRIPTION

cargo fix automatically applies rustc's suggested fixes to source code. Runs cargo check internally and applies machine-applicable suggestions from diagnostics.

PARAMETERS

--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.

EDITION MIGRATION

$ cargo fix --edition
copy
Migrates code from one Rust edition to the next (e.g., 2021 to 2024). After running, update the edition field in Cargo.toml manually.

CAVEATS

Can only fix normally compiled code. Conditionally compiled code requires appropriate --features or --target flags. Built into Cargo since Rust 1.29. By default, requires a clean VCS state; use --allow-dirty or --allow-staged to override.

SEE ALSO

Copied to clipboard
Kai