LinuxCommandLibrary

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

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
--broken-code
Fix code even with existing compiler errors
--allow-dirty
Allow fixes on dirty working directory
--allow-staged
Allow fixes with staged changes
--all-targets
Fix all targets (lib, bins, tests, benches, examples)
--all-features
Enable all features
--features features
Enable specified features
--lib
Fix library only
--bins
Fix all binaries
--tests
Fix all tests
-p, --package spec
Fix specific packages
--workspace
Fix all workspace members

EDITION MIGRATION

$ cargo fix --edition
copy
Migrates code from one Rust edition to the next (e.g., 2018 to 2021).

CAVEATS

Can only fix normally compiled code. Conditionally compiled code requires appropriate --features or --target flags. Built into Cargo since Rust 1.29.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community