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 current working directory. In the root of a
69       virtual workspace, all workspace members are selected (--all is
70       implied). Otherwise, only the package in the current directory will be
71       selected. The default packages may be overridden with the
72       workspace.default-members key in the root Cargo.toml manifest.
73
74       -p SPEC..., --package SPEC...
75           Fix only the specified packages. See cargo-pkgid(1) for the SPEC
76           format. This flag may be specified multiple times.
77
78       --all
79           Fix all members in the workspace.
80
81       --exclude SPEC...
82           Exclude the specified packages. Must be used in conjunction with
83           the --all flag. This flag may be specified multiple times.
84
85   Target Selection
86       When no target selection options are given, cargo fix will fix all
87       targets (--all-targets implied). Binaries are skipped if they have
88       required-features that are missing.
89
90       Passing target selection flags will fix only the specified targets.
91
92       --lib
93           Fix the package’s library.
94
95       --bin NAME...
96           Fix the specified binary. This flag may be specified multiple
97           times.
98
99       --bins
100           Fix all binary targets.
101
102       --example NAME...
103           Fix the specified example. This flag may be specified multiple
104           times.
105
106       --examples
107           Fix all example targets.
108
109       --test NAME...
110           Fix the specified integration test. This flag may be specified
111           multiple times.
112
113       --tests
114           Fix all targets in test mode that have the test = true manifest
115           flag set. By default this includes the library and binaries built
116           as unittests, and integration tests. Be aware that this will also
117           build any required dependencies, so the lib target may be built
118           twice (once as a unittest, and once as a dependency for binaries,
119           integration tests, etc.). Targets may be enabled or disabled by
120           setting the test flag in the manifest settings for the target.
121
122       --bench NAME...
123           Fix the specified benchmark. This flag may be specified multiple
124           times.
125
126       --benches
127           Fix all targets in benchmark mode that have the bench = true
128           manifest flag set. By default this includes the library and
129           binaries built as benchmarks, and bench targets. Be aware that this
130           will also build any required dependencies, so the lib target may be
131           built twice (once as a benchmark, and once as a dependency for
132           binaries, benchmarks, etc.). Targets may be enabled or disabled by
133           setting the bench flag in the manifest settings for the target.
134
135       --all-targets
136           Fix all targets. This is equivalent to specifying --lib --bins
137           --tests --benches --examples.
138
139   Feature Selection
140       When no feature options are given, the default feature is activated for
141       every selected package.
142
143       --features FEATURES
144           Space or comma separated list of features to activate. These
145           features only apply to the current directory’s package. Features of
146           direct dependencies may be enabled with <dep-name>/<feature-name>
147           syntax.
148
149       --all-features
150           Activate all available features of all selected packages.
151
152       --no-default-features
153           Do not activate the default feature of the current directory’s
154           package.
155
156   Compilation Options
157       --target TRIPLE
158           Fix for the given architecture. The default is the host
159           architecture. The general format of the triple is
160           <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
161           a list of supported targets.
162
163           This may also be specified with the build.target config value
164           <https://doc.rust-lang.org/cargo/reference/config.html>.
165
166       --release
167           Fix optimized artifacts with the release profile. See the PROFILES
168           section for details on how this affects profile selection.
169
170       --profile NAME
171           Changes fix behavior. Currently only test is supported, which will
172           fix with the #[cfg(test)] attribute enabled. This is useful to have
173           it fix unit tests which are usually excluded via the cfg attribute.
174           This does not change the actual profile used.
175
176   Output Options
177       --target-dir DIRECTORY
178           Directory for all generated artifacts and intermediate files. May
179           also be specified with the CARGO_TARGET_DIR environment variable,
180           or the build.target-dir config value
181           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
182           to target in the root of the workspace.
183
184   Display Options
185       -v, --verbose
186           Use verbose output. May be specified twice for "very verbose"
187           output which includes extra output such as dependency warnings and
188           build script output. May also be specified with the term.verbose
189           config value
190           <https://doc.rust-lang.org/cargo/reference/config.html>.
191
192       -q, --quiet
193           No output printed to stdout.
194
195       --color WHEN
196           Control when colored output is used. Valid values:
197
198           ·   auto (default): Automatically detect if color support is
199               available on the terminal.
200
201           ·   always: Always display colors.
202
203           ·   never: Never display colors.
204
205           May also be specified with the term.color config value
206           <https://doc.rust-lang.org/cargo/reference/config.html>.
207
208       --message-format FMT
209           The output format for diagnostic messages. Valid values:
210
211           ·   human (default): Display in a human-readable text format.
212
213           ·   json: Emit JSON messages to stdout.
214
215           ·   short: Emit shorter, human-readable text messages.
216
217   Manifest Options
218       --manifest-path PATH
219           Path to the Cargo.toml file. By default, Cargo searches in the
220           current directory or any parent directory for the Cargo.toml file.
221
222       --frozen, --locked
223           Either of these flags requires that the Cargo.lock file is
224           up-to-date. If the lock file is missing, or it needs to be updated,
225           Cargo will exit with an error. The --frozen flag also prevents
226           Cargo from attempting to access the network to determine if it is
227           out-of-date.
228
229           These may be used in environments where you want to assert that the
230           Cargo.lock file is up-to-date (such as a CI build) or want to avoid
231           network access.
232
233   Common Options
234       -h, --help
235           Prints help information.
236
237       -Z FLAG...
238           Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
239           details.
240
241   Miscellaneous Options
242       -j N, --jobs N
243           Number of parallel jobs to run. May also be specified with the
244           build.jobs config value
245           <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults
246           to the number of CPUs.
247

PROFILES

249       Profiles may be used to configure compiler options such as optimization
250       levels and debug settings. See the reference
251       <https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections>
252       for more details.
253
254       Profile selection depends on the target and crate being built. By
255       default the dev or test profiles are used. If the --release flag is
256       given, then the release or bench profiles are used.
257
258       ┌────────────────────┬─────────────────┬───────────────────┐
259       │                    │                 │                   │
260       │Target              │ Default Profile │ --release Profile │
261       ├────────────────────┼─────────────────┼───────────────────┤
262       │                    │                 │                   │
263       │lib, bin, example   │ dev             release           
264       ├────────────────────┼─────────────────┼───────────────────┤
265       │                    │                 │                   │
266       │test, bench, or any │ test            bench             
267       │target              │                 │                   │
268       │in "test" or        │                 │                   │
269       │"bench" mode        │                 │                   │
270       └────────────────────┴─────────────────┴───────────────────┘
271
272       Dependencies use the dev/release profiles.
273

ENVIRONMENT

275       See the reference
276       <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
277       for details on environment variables that Cargo reads.
278

EXIT STATUS

280       0
281           Cargo succeeded.
282
283       101
284           Cargo failed to complete.
285

EXAMPLES

287        1. Apply compiler suggestions to the local package:
288
289               cargo fix
290
291        2. Convert a 2015 edition to 2018:
292
293               cargo fix --edition
294
295        3. Apply suggested idioms for the current edition:
296
297               cargo fix --edition-idioms
298

SEE ALSO

300       cargo(1), cargo-check(1)
301
302
303
304                                  2018-12-20                      CARGO-FIX(1)
Impressum