1CARGO-FIX(1)                                                      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.
87
88       --workspace
89           Fix all members in the workspace.
90
91       --all
92           Deprecated alias for --workspace.
93
94       --exclude SPEC...
95           Exclude the specified packages. Must be used in conjunction with
96           the --workspace flag. This flag may be specified multiple times.
97
98   Target Selection
99       When no target selection options are given, cargo fix will fix all
100       targets (--all-targets implied). Binaries are skipped if they have
101       required-features that are missing.
102
103       Passing target selection flags will fix only the specified targets.
104
105       --lib
106           Fix the package’s library.
107
108       --bin NAME...
109           Fix the specified binary. This flag may be specified multiple
110           times.
111
112       --bins
113           Fix all binary targets.
114
115       --example NAME...
116           Fix the specified example. This flag may be specified multiple
117           times.
118
119       --examples
120           Fix all example targets.
121
122       --test NAME...
123           Fix the specified integration test. This flag may be specified
124           multiple times.
125
126       --tests
127           Fix all targets in test mode that have the test = true manifest
128           flag set. By default this includes the library and binaries built
129           as unittests, and integration tests. Be aware that this will also
130           build any required dependencies, so the lib target may be built
131           twice (once as a unittest, and once as a dependency for binaries,
132           integration tests, etc.). Targets may be enabled or disabled by
133           setting the test flag in the manifest settings for the target.
134
135       --bench NAME...
136           Fix the specified benchmark. This flag may be specified multiple
137           times.
138
139       --benches
140           Fix all targets in benchmark mode that have the bench = true
141           manifest flag set. By default this includes the library and
142           binaries built as benchmarks, and bench targets. Be aware that this
143           will also build any required dependencies, so the lib target may be
144           built twice (once as a benchmark, and once as a dependency for
145           binaries, benchmarks, etc.). Targets may be enabled or disabled by
146           setting the bench flag in the manifest settings for the target.
147
148       --all-targets
149           Fix all targets. This is equivalent to specifying --lib --bins
150           --tests --benches --examples.
151
152   Feature Selection
153       The feature flags allow you to control the enabled features for the
154       "current" package. The "current" package is the package in the current
155       directory, or the one specified in --manifest-path. If running in the
156       root of a virtual workspace, then the default features are selected for
157       all workspace members, or all features if --all-features is specified.
158
159       When no feature options are given, the default feature is activated for
160       every selected package.
161
162       --features FEATURES
163           Space or comma separated list of features to activate. These
164           features only apply to the current directory’s package. Features of
165           direct dependencies may be enabled with <dep-name>/<feature-name>
166           syntax. This flag may be specified multiple times, which enables
167           all specified features.
168
169       --all-features
170           Activate all available features of all selected packages.
171
172       --no-default-features
173           Do not activate the default feature of the current directory’s
174           package.
175
176   Compilation Options
177       --target TRIPLE
178           Fix for the given architecture. The default is the host
179           architecture. The general format of the triple is
180           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
181           a list of supported targets.
182
183           This may also be specified with the build.target config value
184           <https://doc.rust-lang.org/cargo/reference/config.html>.
185
186           Note that specifying this flag makes Cargo run in a different mode
187           where the target artifacts are placed in a separate directory. See
188           the build cache
189           <https://doc.rust-lang.org/cargo/guide/build-cache.html>
190           documentation for more details.
191
192       --release
193           Fix optimized artifacts with the release profile. See the PROFILES
194           section for details on how this affects profile selection.
195
196       --profile NAME
197           Changes fix behavior. Currently only test is supported, which will
198           fix with the #[cfg(test)] attribute enabled. This is useful to have
199           it fix unit tests which are usually excluded via the cfg attribute.
200           This does not change the actual profile used.
201
202   Output Options
203       --target-dir DIRECTORY
204           Directory for all generated artifacts and intermediate files. May
205           also be specified with the CARGO_TARGET_DIR environment variable,
206           or the build.target-dir config value
207           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
208           to target in the root of the workspace.
209
210   Display Options
211       -v, --verbose
212           Use verbose output. May be specified twice for "very verbose"
213           output which includes extra output such as dependency warnings and
214           build script output. May also be specified with the term.verbose
215           config value
216           <https://doc.rust-lang.org/cargo/reference/config.html>.
217
218       -q, --quiet
219           No output printed to stdout.
220
221       --color WHEN
222           Control when colored output is used. Valid values:
223
224           ·   auto (default): Automatically detect if color support is
225               available on the terminal.
226
227           ·   always: Always display colors.
228
229           ·   never: Never display colors.
230
231           May also be specified with the term.color config value
232           <https://doc.rust-lang.org/cargo/reference/config.html>.
233
234       --message-format FMT
235           The output format for diagnostic messages. Can be specified
236           multiple times and consists of comma-separated values. Valid
237           values:
238
239           ·   human (default): Display in a human-readable text format.
240
241           ·   short: Emit shorter, human-readable text messages.
242
243           ·   json: Emit JSON messages to stdout. See the reference
244               <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
245               for more details.
246
247           ·   json-diagnostic-short: Ensure the rendered field of JSON
248               messages contains the "short" rendering from rustc.
249
250           ·   json-diagnostic-rendered-ansi: Ensure the rendered field of
251               JSON messages contains embedded ANSI color codes for respecting
252               rustc’s default color scheme.
253
254           ·   json-render-diagnostics: Instruct Cargo to not include rustc
255               diagnostics in in JSON messages printed, but instead Cargo
256               itself should render the JSON diagnostics coming from rustc.
257               Cargo’s own JSON diagnostics and others coming from rustc are
258               still emitted.
259
260   Manifest Options
261       --manifest-path PATH
262           Path to the Cargo.toml file. By default, Cargo searches for the
263           Cargo.toml file in the current directory or any parent directory.
264
265       --frozen, --locked
266           Either of these flags requires that the Cargo.lock file is
267           up-to-date. If the lock file is missing, or it needs to be updated,
268           Cargo will exit with an error. The --frozen flag also prevents
269           Cargo from attempting to access the network to determine if it is
270           out-of-date.
271
272           These may be used in environments where you want to assert that the
273           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
274           network access.
275
276       --offline
277           Prevents Cargo from accessing the network for any reason. Without
278           this flag, Cargo will stop with an error if it needs to access the
279           network and the network is not available. With this flag, Cargo
280           will attempt to proceed without the network if possible.
281
282           Beware that this may result in different dependency resolution than
283           online mode. Cargo will restrict itself to crates that are
284           downloaded locally, even if there might be a newer version as
285           indicated in the local copy of the index. See the cargo-fetch(1)
286           command to download dependencies before going offline.
287
288           May also be specified with the net.offline config value
289           <https://doc.rust-lang.org/cargo/reference/config.html>.
290
291   Common Options
292       -h, --help
293           Prints help information.
294
295       -Z FLAG...
296           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
297           details.
298
299   Miscellaneous Options
300       -j N, --jobs N
301           Number of parallel jobs to run. May also be specified with the
302           build.jobs config value
303           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
304           to the number of CPUs.
305

PROFILES

307       Profiles may be used to configure compiler options such as optimization
308       levels and debug settings. See the reference
309       <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
310       details.
311
312       Profile selection depends on the target and crate being built. By
313       default the dev or test profiles are used. If the --release flag is
314       given, then the release or bench profiles are used.
315
316       ┌────────────────────┬─────────────────┬───────────────────┐
317       │                    │                 │                   │
318       │Target              │ Default Profile │ --release Profile │
319       ├────────────────────┼─────────────────┼───────────────────┤
320       │                    │                 │                   │
321       │lib, bin, example   │ dev             release           
322       ├────────────────────┼─────────────────┼───────────────────┤
323       │                    │                 │                   │
324       │test, bench, or any │ test            bench             
325       │target              │                 │                   │
326       │in "test" or        │                 │                   │
327       │"bench" mode        │                 │                   │
328       └────────────────────┴─────────────────┴───────────────────┘
329
330       Dependencies use the dev/release profiles.
331

ENVIRONMENT

333       See the reference
334       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
335       for details on environment variables that Cargo reads.
336

EXIT STATUS

338       0
339           Cargo succeeded.
340
341       101
342           Cargo failed to complete.
343

EXAMPLES

345        1. Apply compiler suggestions to the local package:
346
347               cargo fix
348
349        2. Convert a 2015 edition to 2018:
350
351               cargo fix --edition
352
353        3. Apply suggested idioms for the current edition:
354
355               cargo fix --edition-idioms
356

SEE ALSO

358       cargo(1), cargo-check(1)
359
360
361
362                                  2020-02-06                      CARGO-FIX(1)
Impressum