CARGO-FIX(1)
CARGO-FIX(1) β General Commands Manual, bestie edition π
ok so this is the manual for cargo-fix and honestly? it's the "let the compiler do ur homework" subcommand. buckle up π
πΈ NAME πΈ
cargo-fix β Automatically fix lint warnings reported by rustc
β¨ SYNOPSIS β¨
cargo fix [options]
π DESCRIPTION π
okay so basically: this Cargo subcommand scoops up rustc's suggestions from diagnostics like warnings and applies them straight to ur source code. that's it, that's the whole vibe. it exists to automate the stuff rustc already knows how to tell u to fix, so u don't have to sit there going "yes ma'am" to every single warning by hand π
when u run cargo fix, under the hood it's actually running cargo-check(1). every warning that applies to ur crate gets fixed automatically (if it can be fixed), and whatever warnings are left over get printed for u when the check finishes. so like, if u wanna apply all the fixes to the current package, u just run:
cargo fix
and that behaves the same as cargo check --all-targets. cute right?? π«Ά
here's the catch tho β cargo fix can only fix code that gets compiled normally by cargo check. if some code is conditionally enabled behind optional features, u gotta turn those features on so that code actually gets analyzed:
cargo fix --features foo
same energy for other cfg expressions, like platform-specific code β those need --target passed so the code for that target gets fixed:
cargo fix --target x86_64-pc-windows-gnu
if u hit any problems with cargo fix, or u just have questions or feature requests, pls pls pls don't be shy β file an issue at https://github.com/rust-lang/cargo π
π¦ Edition migration π¦
plot twist: the cargo fix subcommand can ALSO migrate a package from one edition to the next. the link for the full lore is https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html.
the general procedure goes like this:
- Run
cargo fix --edition. consider also using the--all-featuresflag if ur project has multiple features. u may also wanna runcargo fix --editionmultiple times with different--targetflags if ur project has platform-specific code gated bycfgattributes. - Modify
Cargo.tomlto set theeditionfield (https://doc.rust-lang.org/cargo/reference/manifest.html#the-edition-field) to the new edition. - Run ur project tests to verify everything still works. if new warnings show up, u might wanna consider running
cargo fixagain (without the--editionflag) to apply any suggestions the compiler hands u.
and hopefully that's literally it!! just keep in mind those caveats from up above: cargo fix cannot update code for inactive features or cfg expressions. also, in some rare cases the compiler can't automatically migrate all the code to the new edition, and that may require manual changes after building with the new edition. no cap π
π OPTIONS π
π Fix options π
--broken-codeβ fix code even if it already has compiler errors. this is useful ifcargo fixfails to apply the changes. it'll apply the changes and leave the broken code sitting in the working directory for u to inspect and manually fix. (yes, on purpose. it's giving "trust the process" π)--editionβ apply changes that will update the code to the next edition. heads up: this will not update the edition in theCargo.tomlmanifest, which has to be updated manually aftercargo fix --editionfinishes.--edition-idiomsβ apply suggestions that will update code to the preferred style for the current edition.--allow-no-vcsβ fix code even if a VCS was not detected.--allow-dirtyβ fix code even if the working directory has changes (including staged changes).--allow-stagedβ fix code even if the working directory has staged changes.
π¦ Package Selection π¦
so by default, when u don't give any package selection options, the packages that get selected depend on the selected manifest file (which is based on the current working directory if --manifest-path isn't given). if the manifest is the root of a workspace, then the workspace's default members get selected β otherwise only the package defined by the manifest gets selected.
the default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. if that's not set, a virtual workspace will include all workspace members (equivalent to passing --workspace), and a non-virtual workspace will include only the root crate itself.
-p*spec*β¦,--package*spec*β¦ β fix only the specified packages. see cargo-pkgid(1) for the SPEC format. this flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. however!! to avoid ur shell accidentally expanding glob patterns before Cargo gets to handle them, u must use single quotes or double quotes around each pattern. don't skip this step bestie π--workspaceβ fix all members in the workspace.--allβ deprecated alias for--workspace. (old but still here, like that one playlist u never delete π)--exclude*SPEC*β¦ β exclude the specified packages. must be used in conjunction with the--workspaceflag. this flag may be specified multiple times and supports common Unix glob patterns like*,?and[]. and same rule as before: to avoid ur shell accidentally expanding glob patterns before Cargo handles them, u must use single quotes or double quotes around each pattern.
π― Target Selection π―
when no target selection options are given, cargo fix will fix all targets (--all-targets implied). binaries get skipped if they have required-features that are missing.
passing target selection flags will fix only the specified targets.
also note that --bin, --example, --test and --bench flags also support common Unix glob patterns like *, ? and []. and yes, once again: to avoid ur shell accidentally expanding glob patterns before Cargo handles them, u must use single quotes or double quotes around each glob pattern. it's a whole thing, iykyk π
--libβ fix the package's library.--bin*name*β¦ β fix the specified binary. this flag may be specified multiple times and supports common Unix glob patterns.--binsβ fix all binary targets.--example*name*β¦ β fix the specified example. this flag may be specified multiple times and supports common Unix glob patterns.--examplesβ fix all example targets.--test*name*β¦ β fix the specified integration test. this flag may be specified multiple times and supports common Unix glob patterns.--testsβ fix all targets that have thetest = truemanifest flag set. by default this includes the library and binaries built as unittests, and integration tests. be aware that this will also build any required dependencies, so the lib target may be built twice (once as a unittest, and once as a dependency for binaries, integration tests, etc.). targets may be enabled or disabled by setting thetestflag in the manifest settings for the target. double-build, double-slay, double the wait π--bench*name*β¦ β fix the specified benchmark. this flag may be specified multiple times and supports common Unix glob patterns.--benchesβ fix all targets that have thebench = truemanifest flag set. by default this includes the library and binaries built as benchmarks, and bench targets. be aware that this will also build any required dependencies, so the lib target may be built twice (once as a benchmark, and once as a dependency for binaries, benchmarks, etc.). targets may be enabled or disabled by setting thebenchflag in the manifest settings for the target.--all-targetsβ fix all targets. this is equivalent to specifying--lib --bins --tests --benches --examples. the "everything bagel" option fr fr π₯―
π Feature Selection π
the feature flags let u control which features are enabled. when no feature options are given, the default feature is activated for every selected package.
more deets live in the features documentation at https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options.
-Ffeatures,--featuresfeatures β space or comma separated list of features to activate. features of workspace members may be enabled withpackage-name/feature-namesyntax. this flag may be specified multiple times, which enables all specified features.--all-featuresβ activate all available features of all selected packages.--no-default-featuresβ do not activate thedefaultfeature of the selected packages.
π οΈ Compilation Options π οΈ
--targettriple β fix for the specified target architecture. this flag may be specified multiple times. the default is the host architecture. the general format of the triple is<arch><sub>-<vendor>-<sys>-<abi>.
possible values:
- any supported target in
rustc --print target-list. "host-tuple", which will internally be substituted by the host's target. this can be particularly useful if ur cross-compiling some crates and don't wanna specify ur host's machine as a target (for instance, an xtask in a shared project that may be worked on by many hosts).- a path to a custom target specification. see Custom Target Lookup Path at
https://doc.rust-lang.org/rustc/targets/custom.html#custom-target-lookup-pathfor more information.
this may also be specified with the build.target config value at https://doc.rust-lang.org/cargo/reference/config.html.
β οΈ note that specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. see the build cache documentation at https://doc.rust-lang.org/cargo/reference/build-cache.html for more details.
-r,--releaseβ fix optimized artifacts with thereleaseprofile. see also the--profileoption for choosing a specific profile by name.--profilename β fix with the given profile.
as a special case, specifying the test profile will also enable checking in test mode, which will enable checking tests and enable the test cfg option. see rustc tests at https://doc.rust-lang.org/rustc/tests/index.html for more detail.
see the reference at https://doc.rust-lang.org/cargo/reference/profiles.html for more details on profiles.
--timings=fmts β output information on how long each compilation takes, and track concurrency information over time. accepts an optional comma-separated list of output formats;--timingswithout an argument will default to--timings=html. specifying an output format (rather than the default) is unstable and requires-Zunstable-options. valid output formats:htmlβ unstable, so you need-Zunstable-optionsfor this one, bestie. It writes a human-readable file calledcargo-timing.htmlinto thetarget/cargo-timingsdirectory, with a whole report of the compilation in it. It also drops a report into that same directory with a timestamp in the filename, so you can go back and snoop on your older runs like the archive girlie you are. Heads up though: HTML output is for human consumption only β it does not give you machine-readable timing data. πjsonβ unstable too, also requires-Zunstable-options. This one emits machine-readable JSON info about timing information. Robots love it. π€β¨
π«Ά Output Options π«Ά
--target-dirdirectory β the directory where all your generated artifacts and intermediate files go. You can also set this with theCARGO_TARGET_DIRenvironment variable, or with thebuild.target-dirconfig value (https://doc.rust-lang.org/cargo/reference/config.html). If you don't say anything, it defaults totargetin the root of the workspace. π―
π Display Options π
-v,--verboseβ verbose output, aka the tea-spilling mode. You can pass it twice for "very verbose" output, which throws in extra stuff like dependency warnings and build script output. You can also set this with theterm.verboseconfig value (https://doc.rust-lang.org/cargo/reference/config.html). π-q,--quietβ do not print cargo log messages. Silence, iconic, peaceful. May also be set with theterm.quietconfig value (https://doc.rust-lang.org/cargo/reference/config.html). π€«--colorwhen β controls when colored output happens. Valid values, periodt:auto(this is the default) β automatically detects whether your terminal can do color support.alwaysβ always display colors. no thoughts, just vibrancy. πneverβ never display colors. greyscale era.
May also be set with the term.color config value (https://doc.rust-lang.org/cargo/reference/config.html).
--message-formatfmt β the output format for diagnostic messages. You can specify it multiple times, and it's made of comma-separated values. Valid values:human(the default) β display in a human-readable text format. Conflicts withshortandjson.shortβ emit shorter, human-readable text messages. Conflicts withhumanandjson.jsonβ emit JSON messages to stdout. See the reference athttps://doc.rust-lang.org/cargo/reference/external-tools.html#json-messagesfor more details. Conflicts withhumanandshort.json-diagnostic-shortβ makes sure therenderedfield of JSON messages contains the "short" rendering from rustc. Cannot be used withhumanorshort.json-diagnostic-rendered-ansiβ makes sure therenderedfield of JSON messages contains embedded ANSI color codes, so it respects rustc's default color scheme. Cannot be used withhumanorshort.json-render-diagnosticsβ tells Cargo to not include rustc diagnostics in the JSON messages it prints, and instead have Cargo itself render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and the other ones coming from rustc are still emitted. Cannot be used withhumanorshort.
π Manifest Options π
--manifest-pathpath β path to theCargo.tomlfile. By default, Cargo goes looking forCargo.tomlin the current directory, or any parent directory. like it's searching for its friends in a crowd. π΅οΈββοΈ--ignore-rust-versionβ ignore therust-versionspecification in packages. who even is she π--lockedβ asserts that the exact same dependencies and versions are used as when the existingCargo.lockfile was originally generated. Cargo will exit with an error when either of these scenarios pops up:- The lock file is missing.
- Cargo attempted to change the lock file due to a different dependency resolution.
You'd use this in environments where you want deterministic builds, like CI pipelines. no surprises, no plot twists. π
--offlineβ stops Cargo from accessing the network for any reason. Without this flag, Cargo will stop with an error if it needs the network and the network isn't available. With this flag, Cargo will try to proceed without the network if it possibly can.
β οΈ Beware, bestie β this may result in a different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. See the cargo-fetch(1) command to download dependencies before going offline.
May also be set with the net.offline config value (https://doc.rust-lang.org/cargo/reference/config.html). βοΈ
--frozenβ equivalent to specifying both--lockedand--offlineat the same time. two for one, slay. π§--lockfile-pathPATH β changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end withCargo.lock, e.g.--lockfile-path /tmp/temporary-lockfile/Cargo.lock. Note that providing--lockfile-pathwill ignore the existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. You can use this flag to run most commands in read-only directories, writing the lockfile into the provided PATH.
This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag to enable β see #14421 (https://github.com/rust-lang/cargo/issues/14421). π
π Common Options π
+toolchain β if Cargo was installed with rustup, and the first argument tocargobegins with+, it gets interpreted as a rustup toolchain name (like+stableor+nightly). See the rustup documentation athttps://rust-lang.github.io/rustup/overrides.htmlfor more info about how toolchain overrides work. β¨--configKEY=VALUE or PATH β overrides a Cargo configuration value. The argument should be in TOML syntax ofKEY=VALUE, or given as a path to an extra configuration file. You can specify this flag multiple times. See the command-line overrides section athttps://doc.rust-lang.org/cargo/reference/config.html#command-line-overridesfor more info. π§-CPATH β changes the current working directory before executing any specified operations. This affects stuff like where cargo looks by default for the project manifest (Cargo.toml), and also the directories it searches to discover.cargo/config.toml, for example. This option must appear before the command name, like this:
cargo -C path/to/my-project build
This option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the-Z unstable-optionsflag to enable β see #10098 (https://github.com/rust-lang/cargo/issues/10098). π
-h,--helpβ prints help information. your bestie when you're lost. π«Ά-Zflag β unstable (nightly-only) flags for Cargo. Runcargo -Z helpfor details. π§ͺ
π Miscellaneous Options π
-jN,--jobsN β the number of parallel jobs to run. May also be set with thebuild.jobsconfig value (https://doc.rust-lang.org/cargo/reference/config.html). It defaults to the number of logical CPUs. If it's negative, it sets the maximum number of parallel jobs to the number of logical CPUs plus the value you provided. If a stringdefaultis provided, it sets the value back to defaults. And it should not be0. π«--keep-goingβ build as many crates in the dependency graph as possible, rather than aborting the build on the first one that fails to build.
For example, if the current package depends on dependencies fails and works, one of which fails to build, cargo fix -j1 may or may not build the one that succeeds (depending on which one of the two builds Cargo picked to run first), whereas cargo fix -j1 --keep-going would definitely run both builds, even if the one run first fails. resilience, main character energy. π
πΈ ENVIRONMENT πΈ
See the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for all the deets on environment variables that Cargo reads. π±
β EXIT STATUS β
0β Cargo succeeded. we ate. π101β Cargo failed to complete. it's giving tragedy. π
π¦ EXAMPLES π¦
- Apply compiler suggestions to the local package:
cargo fix
- Update a package to prepare it for the next edition:
cargo fix --edition
- Apply suggested idioms for the current edition:
cargo fix --edition-idioms
π SEE ALSO π
cargo(1), cargo-check(1) β go read those too, bestie, they're iconic. π«Ά
and that's the whole page, fr fr π this was CARGO-FIX(1) β that's the source/version tag at the bottom, your little footer crown, dated and everything. now go fix your code, you absolute legend β¨π
π¦ where this page comes from
- ubuntu resolute: cargo-1.93 1.93.1+dfsg-0ubuntu6 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms