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. Similarly if you’d
28       like to fix code for different platforms you can do:
29
30           cargo fix --edition --target x86_64-pc-windows-gnu
31
32       or if your crate has optional features:
33
34           cargo fix --edition --no-default-features --features foo
35
36       If you encounter any problems with cargo fix or otherwise have any
37       questions or feature requests please don’t hesitate to file an issue at
38       https://github.com/rust-lang/cargo
39

OPTIONS

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

PROFILES

288       Profiles may be used to configure compiler options such as optimization
289       levels and debug settings. See the reference
290       <https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections>
291       for more details.
292
293       Profile selection depends on the target and crate being built. By
294       default the dev or test profiles are used. If the --release flag is
295       given, then the release or bench profiles are used.
296
297       ┌────────────────────┬─────────────────┬───────────────────┐
298       │                    │                 │                   │
299       │Target              │ Default Profile │ --release Profile │
300       ├────────────────────┼─────────────────┼───────────────────┤
301       │                    │                 │                   │
302       │lib, bin, example   │ dev             release           
303       ├────────────────────┼─────────────────┼───────────────────┤
304       │                    │                 │                   │
305       │test, bench, or any │ test            bench             
306       │target              │                 │                   │
307       │in "test" or        │                 │                   │
308       │"bench" mode        │                 │                   │
309       └────────────────────┴─────────────────┴───────────────────┘
310
311       Dependencies use the dev/release profiles.
312

ENVIRONMENT

314       See the reference
315       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
316       for details on environment variables that Cargo reads.
317

EXIT STATUS

319       0
320           Cargo succeeded.
321
322       101
323           Cargo failed to complete.
324

EXAMPLES

326        1. Apply compiler suggestions to the local package:
327
328               cargo fix
329
330        2. Convert a 2015 edition to 2018:
331
332               cargo fix --edition
333
334        3. Apply suggested idioms for the current edition:
335
336               cargo fix --edition-idioms
337

SEE ALSO

339       cargo(1), cargo-check(1)
340
341
342
343                                  2019-08-19                      CARGO-FIX(1)
Impressum