1CARGO-FIX(1)                General Commands Manual               CARGO-FIX(1)
2
3
4

NAME

6       cargo-fix - Automatically fix lint warnings reported by rustc
7

SYNOPSIS

9       cargo fix [options]
10

DESCRIPTION

12       This Cargo subcommand will automatically take rustc's suggestions from
13       diagnostics like warnings and apply them to your source code. This is
14       intended to help automate tasks that rustc itself already knows how to
15       tell you to fix! The cargo fix subcommand is also being developed for
16       the Rust 2018 edition to provide code the ability to easily opt-in to
17       the new edition without having to worry about any breakage.
18
19       Executing cargo fix will under the hood execute cargo-check(1). Any
20       warnings applicable to your crate will be automatically fixed (if
21       possible) and all remaining warnings will be displayed when the check
22       process is finished. For example if you'd like to prepare for the 2018
23       edition, you can do so by executing:
24
25           cargo fix --edition
26
27       which behaves the same as cargo check --all-targets.
28
29       cargo fix is only capable of fixing code that is normally compiled with
30       cargo check. If code is conditionally enabled with optional features,
31       you will need to enable those features for that code to be analyzed:
32
33           cargo fix --edition --features foo
34
35       Similarly, other cfg expressions like platform-specific code will need
36       to pass --target to fix code for the given target.
37
38           cargo fix --edition --target x86_64-pc-windows-gnu
39
40       If you encounter any problems with cargo fix or otherwise have any
41       questions or feature requests please don't hesitate to file an issue at
42       <https://github.com/rust-lang/cargo>
43

OPTIONS

45   Fix options
46       --broken-code
47           Fix code even if it already has compiler errors. This is useful if
48           cargo fix fails to apply the changes. It will apply the changes and
49           leave the broken code in the working directory for you to inspect
50           and manually fix.
51
52       --edition
53           Apply changes that will update the code to the latest edition. This
54           will not update the edition in the Cargo.toml manifest, which must
55           be updated manually.
56
57       --edition-idioms
58           Apply suggestions that will update code to the preferred style for
59           the current edition.
60
61       --allow-no-vcs
62           Fix code even if a VCS was not detected.
63
64       --allow-dirty
65           Fix code even if the working directory has changes.
66
67       --allow-staged
68           Fix code even if the working directory has staged changes.
69
70   Package Selection
71       By default, when no package selection options are given, the packages
72       selected depend on the selected manifest file (based on the current
73       working directory if --manifest-path is not given). If the manifest is
74       the root of a workspace then the workspaces default members are
75       selected, otherwise only the package defined by the manifest will be
76       selected.
77
78       The default members of a workspace can be set explicitly with the
79       workspace.default-members key in the root manifest. If this is not set,
80       a virtual workspace will include all workspace members (equivalent to
81       passing --workspace), and a non-virtual workspace will include only the
82       root crate itself.
83
84       -p spec..., --package spec...
85           Fix only the specified packages. See cargo-pkgid(1) for the SPEC
86           format. This flag may be specified multiple times and supports
87           common Unix glob patterns like *, ? and []. However, to avoid your
88           shell accidentally expanding glob patterns before Cargo handles
89           them, you must use single quotes or double quotes around each
90           pattern.
91
92       --workspace
93           Fix all members in the workspace.
94
95       --all
96           Deprecated alias for --workspace.
97
98       --exclude SPEC...
99           Exclude the specified packages. Must be used in conjunction with
100           the --workspace flag. This flag may be specified multiple times and
101           supports common Unix glob patterns like *, ? and []. However, to
102           avoid your shell accidentally expanding glob patterns before Cargo
103           handles them, you must use single quotes or double quotes around
104           each pattern.
105
106   Target Selection
107       When no target selection options are given, cargo fix will fix all
108       targets (--all-targets implied). Binaries are skipped if they have
109       required-features that are missing.
110
111       Passing target selection flags will fix only the specified targets.
112
113       Note that --bin, --example, --test and --bench flags also support
114       common Unix glob patterns like *, ? and []. However, to avoid your
115       shell accidentally expanding glob patterns before Cargo handles them,
116       you must use single quotes or double quotes around each glob pattern.
117
118       --lib
119           Fix the package's library.
120
121       --bin name...
122           Fix the specified binary. This flag may be specified multiple times
123           and supports common Unix glob patterns.
124
125       --bins
126           Fix all binary targets.
127
128       --example name...
129           Fix the specified example. This flag may be specified multiple
130           times and supports common Unix glob patterns.
131
132       --examples
133           Fix all example targets.
134
135       --test name...
136           Fix the specified integration test. This flag may be specified
137           multiple times and supports common Unix glob patterns.
138
139       --tests
140           Fix all targets in test mode that have the test = true manifest
141           flag set. By default this includes the library and binaries built
142           as unittests, and integration tests. Be aware that this will also
143           build any required dependencies, so the lib target may be built
144           twice (once as a unittest, and once as a dependency for binaries,
145           integration tests, etc.). Targets may be enabled or disabled by
146           setting the test flag in the manifest settings for the target.
147
148       --bench name...
149           Fix the specified benchmark. This flag may be specified multiple
150           times and supports common Unix glob patterns.
151
152       --benches
153           Fix all targets in benchmark mode that have the bench = true
154           manifest flag set. By default this includes the library and
155           binaries built as benchmarks, and bench targets. Be aware that this
156           will also build any required dependencies, so the lib target may be
157           built twice (once as a benchmark, and once as a dependency for
158           binaries, benchmarks, etc.). Targets may be enabled or disabled by
159           setting the bench flag in the manifest settings for the target.
160
161       --all-targets
162           Fix all targets. This is equivalent to specifying --lib --bins
163           --tests --benches --examples.
164
165   Feature Selection
166       The feature flags allow you to control which features are enabled. When
167       no feature options are given, the default feature is activated for
168       every selected package.
169
170       See the features documentation
171       <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
172       for more details.
173
174       --features features
175           Space or comma separated list of features to activate. Features of
176           workspace members may be enabled with package-name/feature-name
177           syntax. This flag may be specified multiple times, which enables
178           all specified features.
179
180       --all-features
181           Activate all available features of all selected packages.
182
183       --no-default-features
184           Do not activate the default feature of the selected packages.
185
186   Compilation Options
187       --target triple
188           Fix for the given architecture. The default is the host
189           architecture. The general format of the triple is
190           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
191           a list of supported targets.
192
193           This may also be specified with the build.target config value
194           <https://doc.rust-lang.org/cargo/reference/config.html>.
195
196           Note that specifying this flag makes Cargo run in a different mode
197           where the target artifacts are placed in a separate directory. See
198           the build cache
199           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
200           documentation for more details.
201
202       --release
203           Fix optimized artifacts with the release profile. See the PROFILES
204           section for details on how this affects profile selection.
205
206       --profile name
207           Changes fix behavior. Currently only test is supported, which will
208           fix with the #[cfg(test)] attribute enabled. This is useful to have
209           it fix unit tests which are usually excluded via the cfg attribute.
210           This does not change the actual profile used.
211
212   Output Options
213       --target-dir directory
214           Directory for all generated artifacts and intermediate files. May
215           also be specified with the CARGO_TARGET_DIR environment variable,
216           or the build.target-dir config value
217           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
218           to target in the root of the workspace.
219
220   Display Options
221       -v, --verbose
222           Use verbose output. May be specified twice for "very verbose"
223           output which includes extra output such as dependency warnings and
224           build script output. May also be specified with the term.verbose
225           config value
226           <https://doc.rust-lang.org/cargo/reference/config.html>.
227
228       -q, --quiet
229           No output printed to stdout.
230
231       --color when
232           Control when colored output is used. Valid values:
233
234           ·  auto (default): Automatically detect if color support is
235               available on the terminal.
236
237           ·  always: Always display colors.
238
239           ·  never: Never display colors.
240
241           May also be specified with the term.color config value
242           <https://doc.rust-lang.org/cargo/reference/config.html>.
243
244       --message-format fmt
245           The output format for diagnostic messages. Can be specified
246           multiple times and consists of comma-separated values. Valid
247           values:
248
249           ·  human (default): Display in a human-readable text format.
250
251           ·  short: Emit shorter, human-readable text messages.
252
253           ·  json: Emit JSON messages to stdout. See the reference
254               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
255               for more details.
256
257           ·  json-diagnostic-short: Ensure the rendered field of JSON
258               messages contains the "short" rendering from rustc.
259
260           ·  json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
261               messages contains embedded ANSI color codes for respecting
262               rustc's default color scheme.
263
264           ·  json-render-diagnostics: Instruct Cargo to not include rustc
265               diagnostics in in JSON messages printed, but instead Cargo
266               itself should render the JSON diagnostics coming from rustc.
267               Cargo's own JSON diagnostics and others coming from rustc are
268               still emitted.
269
270   Manifest Options
271       --manifest-path path
272           Path to the Cargo.toml file. By default, Cargo searches for the
273           Cargo.toml file in the current directory or any parent directory.
274
275       --frozen, --locked
276           Either of these flags requires that the Cargo.lock file is
277           up-to-date. If the lock file is missing, or it needs to be updated,
278           Cargo will exit with an error. The --frozen flag also prevents
279           Cargo from attempting to access the network to determine if it is
280           out-of-date.
281
282           These may be used in environments where you want to assert that the
283           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
284           network access.
285
286       --offline
287           Prevents Cargo from accessing the network for any reason. Without
288           this flag, Cargo will stop with an error if it needs to access the
289           network and the network is not available. With this flag, Cargo
290           will attempt to proceed without the network if possible.
291
292           Beware that this may result in different dependency resolution than
293           online mode. Cargo will restrict itself to crates that are
294           downloaded locally, even if there might be a newer version as
295           indicated in the local copy of the index. See the cargo-fetch(1)
296           command to download dependencies before going offline.
297
298           May also be specified with the net.offline config value
299           <https://doc.rust-lang.org/cargo/reference/config.html>.
300
301   Common Options
302       +toolchain
303           If Cargo has been installed with rustup, and the first argument to
304           cargo begins with +, it will be interpreted as a rustup toolchain
305           name (such as +stable or +nightly). See the rustup documentation
306           <https://rust-lang.github.io/rustup/overrides.html> for more
307           information about how toolchain overrides work.
308
309       -h, --help
310           Prints help information.
311
312       -Z flag
313           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
314           details.
315
316   Miscellaneous Options
317       -j N, --jobs N
318           Number of parallel jobs to run. May also be specified with the
319           build.jobs config value
320           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
321           to the number of CPUs.
322

PROFILES

324       Profiles may be used to configure compiler options such as optimization
325       levels and debug settings. See the reference
326       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
327       details.
328
329       Profile selection depends on the target and crate being built. By
330       default the dev or test profiles are used. If the --release flag is
331       given, then the release or bench profiles are used.
332
333
334       ┌────────────────────┬─────────────────┬───────────────────┐
335       │Target              │ Default Profile │ --release Profile │
336       ├────────────────────┼─────────────────┼───────────────────┤
337       │lib, bin, example   │ dev             release           
338       ├────────────────────┼─────────────────┼───────────────────┤
339       │test, bench, or any │ test            bench             
340       │target in "test" or │                 │                   │
341       │"bench" mode        │                 │                   │
342       └────────────────────┴─────────────────┴───────────────────┘
343
344       Dependencies use the dev/release profiles.
345

ENVIRONMENT

347       See the reference
348       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
349       for details on environment variables that Cargo reads.
350

EXIT STATUS

352       ·  0: Cargo succeeded.
353
354       ·  101: Cargo failed to complete.
355

EXAMPLES

357        1. Apply compiler suggestions to the local package:
358
359               cargo fix
360
361        2. Convert a 2015 edition to 2018:
362
363               cargo fix --edition
364
365        3. Apply suggested idioms for the current edition:
366
367               cargo fix --edition-idioms
368

SEE ALSO

370       cargo(1), cargo-check(1)
371
372
373
374                                                                  CARGO-FIX(1)
Impressum