blob: 25ac7e7e773eb73ec51c64e8cae7de4452f5d18c [file] [log] [blame]
Matthew Maurerbd398542019-09-05 16:25:08 -07001'\" t
2.\" Title: cargo-fix
3.\" Author: [see the "AUTHOR(S)" section]
4.\" Generator: Asciidoctor 1.5.8
5.\" Date: 2019-04-16
6.\" Manual: \ \&
7.\" Source: \ \&
8.\" Language: English
9.\"
10.TH "CARGO\-FIX" "1" "2019-04-16" "\ \&" "\ \&"
11.ie \n(.g .ds Aq \(aq
12.el .ds Aq '
13.ss \n[.ss] 0
14.nh
15.ad l
16.de URL
17\fI\\$2\fP <\\$1>\\$3
18..
19.als MTO URL
20.if \n[.g] \{\
21. mso www.tmac
22. am URL
23. ad l
24. .
25. am MTO
26. ad l
27. .
28. LINKSTYLE blue R < >
29.\}
30.SH "NAME"
31cargo\-fix \- Automatically fix lint warnings reported by rustc
32.SH "SYNOPSIS"
33.sp
34\fBcargo fix [\fIOPTIONS\fP]\fP
35.SH "DESCRIPTION"
36.sp
37This Cargo subcommand will automatically take rustc\(cqs suggestions from
38diagnostics like warnings and apply them to your source code. This is intended
39to help automate tasks that rustc itself already knows how to tell you to fix!
40The \fBcargo fix\fP subcommand is also being developed for the Rust 2018 edition
41to provide code the ability to easily opt\-in to the new edition without having
42to worry about any breakage.
43.sp
44Executing \fBcargo fix\fP will under the hood execute \fBcargo\-check\fP(1). Any warnings
45applicable to your crate will be automatically fixed (if possible) and all
46remaining warnings will be displayed when the check process is finished. For
47example if you\(cqd like to prepare for the 2018 edition, you can do so by
48executing:
49.sp
50.if n .RS 4
51.nf
52cargo fix \-\-edition
53.fi
54.if n .RE
55.sp
56which behaves the same as \fBcargo check \-\-all\-targets\fP. Similarly if you\(cqd like
57to fix code for different platforms you can do:
58.sp
59.if n .RS 4
60.nf
61cargo fix \-\-edition \-\-target x86_64\-pc\-windows\-gnu
62.fi
63.if n .RE
64.sp
65or if your crate has optional features:
66.sp
67.if n .RS 4
68.nf
69cargo fix \-\-edition \-\-no\-default\-features \-\-features foo
70.fi
71.if n .RE
72.sp
73If you encounter any problems with \fBcargo fix\fP or otherwise have any questions
74or feature requests please don\(cqt hesitate to file an issue at
75.URL "https://github.com/rust\-lang/cargo" "" ""
76.SH "OPTIONS"
77.SS "Fix options"
78.sp
79\fB\-\-broken\-code\fP
80.RS 4
81Fix code even if it already has compiler errors. This is useful if \fBcargo
82fix\fP fails to apply the changes. It will apply the changes and leave the
83broken code in the working directory for you to inspect and manually fix.
84.RE
85.sp
86\fB\-\-edition\fP
87.RS 4
88Apply changes that will update the code to the latest edition. This will
89not update the edition in the \fBCargo.toml\fP manifest, which must be updated
90manually.
91.RE
92.sp
93\fB\-\-edition\-idioms\fP
94.RS 4
95Apply suggestions that will update code to the preferred style for the
96current edition.
97.RE
98.sp
99\fB\-\-allow\-no\-vcs\fP
100.RS 4
101Fix code even if a VCS was not detected.
102.RE
103.sp
104\fB\-\-allow\-dirty\fP
105.RS 4
106Fix code even if the working directory has changes.
107.RE
108.sp
109\fB\-\-allow\-staged\fP
110.RS 4
111Fix code even if the working directory has staged changes.
112.RE
113.SS "Package Selection"
114.sp
115By default, when no package selection options are given, the packages selected
116depend on the current working directory. In the root of a virtual workspace,
117all workspace members are selected (\fB\-\-all\fP is implied). Otherwise, only the
118package in the current directory will be selected. The default packages may be
119overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
120manifest.
121.sp
122\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
123.RS 4
124Fix only the specified packages. See \fBcargo\-pkgid\fP(1) for the
125SPEC format. This flag may be specified multiple times.
126.RE
127.sp
128\fB\-\-all\fP
129.RS 4
130Fix all members in the workspace.
131.RE
132.sp
133\fB\-\-exclude\fP \fISPEC\fP...
134.RS 4
135Exclude the specified packages. Must be used in conjunction with the
136\fB\-\-all\fP flag. This flag may be specified multiple times.
137.RE
138.SS "Target Selection"
139.sp
140When no target selection options are given, \fBcargo fix\fP will fix all targets
141(\fB\-\-all\-targets\fP implied). Binaries are skipped if they have
142\fBrequired\-features\fP that are missing.
143.sp
144Passing target selection flags will fix only the
145specified targets.
146.sp
147\fB\-\-lib\fP
148.RS 4
149Fix the package\(cqs library.
150.RE
151.sp
152\fB\-\-bin\fP \fINAME\fP...
153.RS 4
154Fix the specified binary. This flag may be specified multiple times.
155.RE
156.sp
157\fB\-\-bins\fP
158.RS 4
159Fix all binary targets.
160.RE
161.sp
162\fB\-\-example\fP \fINAME\fP...
163.RS 4
164Fix the specified example. This flag may be specified multiple times.
165.RE
166.sp
167\fB\-\-examples\fP
168.RS 4
169Fix all example targets.
170.RE
171.sp
172\fB\-\-test\fP \fINAME\fP...
173.RS 4
174Fix the specified integration test. This flag may be specified multiple
175times.
176.RE
177.sp
178\fB\-\-tests\fP
179.RS 4
180Fix all targets in test mode that have the \fBtest = true\fP manifest
181flag set. By default this includes the library and binaries built as
182unittests, and integration tests. Be aware that this will also build any
183required dependencies, so the lib target may be built twice (once as a
184unittest, and once as a dependency for binaries, integration tests, etc.).
185Targets may be enabled or disabled by setting the \fBtest\fP flag in the
186manifest settings for the target.
187.RE
188.sp
189\fB\-\-bench\fP \fINAME\fP...
190.RS 4
191Fix the specified benchmark. This flag may be specified multiple times.
192.RE
193.sp
194\fB\-\-benches\fP
195.RS 4
196Fix all targets in benchmark mode that have the \fBbench = true\fP
197manifest flag set. By default this includes the library and binaries built
198as benchmarks, and bench targets. Be aware that this will also build any
199required dependencies, so the lib target may be built twice (once as a
200benchmark, and once as a dependency for binaries, benchmarks, etc.).
201Targets may be enabled or disabled by setting the \fBbench\fP flag in the
202manifest settings for the target.
203.RE
204.sp
205\fB\-\-all\-targets\fP
206.RS 4
207Fix all targets. This is equivalent to specifying \fB\-\-lib \-\-bins
208\-\-tests \-\-benches \-\-examples\fP.
209.RE
210.SS "Feature Selection"
211.sp
212When no feature options are given, the \fBdefault\fP feature is activated for
213every selected package.
214.sp
215\fB\-\-features\fP \fIFEATURES\fP
216.RS 4
217Space or comma separated list of features to activate. These features only
218apply to the current directory\(cqs package. Features of direct dependencies
219may be enabled with \fB<dep\-name>/<feature\-name>\fP syntax.
220.RE
221.sp
222\fB\-\-all\-features\fP
223.RS 4
224Activate all available features of all selected packages.
225.RE
226.sp
227\fB\-\-no\-default\-features\fP
228.RS 4
229Do not activate the \fBdefault\fP feature of the current directory\(cqs
230package.
231.RE
232.SS "Compilation Options"
233.sp
234\fB\-\-target\fP \fITRIPLE\fP
235.RS 4
236Fix for the given architecture. The default is the host
237architecture. The general format of the triple is
238\fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fP. Run \fBrustc \-\-print target\-list\fP for a
239list of supported targets.
240.sp
241This may also be specified with the \fBbuild.target\fP
242.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
243.RE
244.sp
245\fB\-\-release\fP
246.RS 4
247Fix optimized artifacts with the \fBrelease\fP profile. See the
248PROFILES section for details on how this affects profile selection.
249.RE
250.sp
251\fB\-\-profile\fP \fINAME\fP
252.RS 4
253Changes fix behavior. Currently only \fBtest\fP is
254supported, which will fix with the
255\fB#[cfg(test)]\fP attribute enabled. This is useful to have it
256fix unit tests which are usually excluded via
257the \fBcfg\fP attribute. This does not change the actual profile used.
258.RE
259.SS "Output Options"
260.sp
261\fB\-\-target\-dir\fP \fIDIRECTORY\fP
262.RS 4
263Directory for all generated artifacts and intermediate files. May also be
264specified with the \fBCARGO_TARGET_DIR\fP environment variable, or the
265\fBbuild.target\-dir\fP \c
266.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
267Defaults
268to \fBtarget\fP in the root of the workspace.
269.RE
270.SS "Display Options"
271.sp
272\fB\-v\fP, \fB\-\-verbose\fP
273.RS 4
274Use verbose output. May be specified twice for "very verbose" output which
275includes extra output such as dependency warnings and build script output.
276May also be specified with the \fBterm.verbose\fP
277.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
278.RE
279.sp
280\fB\-q\fP, \fB\-\-quiet\fP
281.RS 4
282No output printed to stdout.
283.RE
284.sp
285\fB\-\-color\fP \fIWHEN\fP
286.RS 4
287Control when colored output is used. Valid values:
288.sp
289.RS 4
290.ie n \{\
291\h'-04'\(bu\h'+03'\c
292.\}
293.el \{\
294. sp -1
295. IP \(bu 2.3
296.\}
297\fBauto\fP (default): Automatically detect if color support is available on the
298terminal.
299.RE
300.sp
301.RS 4
302.ie n \{\
303\h'-04'\(bu\h'+03'\c
304.\}
305.el \{\
306. sp -1
307. IP \(bu 2.3
308.\}
309\fBalways\fP: Always display colors.
310.RE
311.sp
312.RS 4
313.ie n \{\
314\h'-04'\(bu\h'+03'\c
315.\}
316.el \{\
317. sp -1
318. IP \(bu 2.3
319.\}
320\fBnever\fP: Never display colors.
321.RE
322.sp
323May also be specified with the \fBterm.color\fP
324.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
325.RE
326.sp
327\fB\-\-message\-format\fP \fIFMT\fP
328.RS 4
329The output format for diagnostic messages. Valid values:
330.sp
331.RS 4
332.ie n \{\
333\h'-04'\(bu\h'+03'\c
334.\}
335.el \{\
336. sp -1
337. IP \(bu 2.3
338.\}
339\fBhuman\fP (default): Display in a human\-readable text format.
340.RE
341.sp
342.RS 4
343.ie n \{\
344\h'-04'\(bu\h'+03'\c
345.\}
346.el \{\
347. sp -1
348. IP \(bu 2.3
349.\}
350\fBjson\fP: Emit JSON messages to stdout.
351.RE
352.sp
353.RS 4
354.ie n \{\
355\h'-04'\(bu\h'+03'\c
356.\}
357.el \{\
358. sp -1
359. IP \(bu 2.3
360.\}
361\fBshort\fP: Emit shorter, human\-readable text messages.
362.RE
363.RE
364.SS "Manifest Options"
365.sp
366\fB\-\-manifest\-path\fP \fIPATH\fP
367.RS 4
368Path to the \fBCargo.toml\fP file. By default, Cargo searches in the current
369directory or any parent directory for the \fBCargo.toml\fP file.
370.RE
371.sp
372\fB\-\-frozen\fP, \fB\-\-locked\fP
373.RS 4
374Either of these flags requires that the \fBCargo.lock\fP file is
375up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will
376exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from
377attempting to access the network to determine if it is out\-of\-date.
378.sp
379These may be used in environments where you want to assert that the
380\fBCargo.lock\fP file is up\-to\-date (such as a CI build) or want to avoid network
381access.
382.RE
383.sp
384\fB\-\-offline\fP
385.RS 4
386Prevents Cargo from accessing the network for any reason. Without this
387flag, Cargo will stop with an error if it needs to access the network and
388the network is not available. With this flag, Cargo will attempt to
389proceed without the network if possible.
390.sp
391Beware that this may result in different dependency resolution than online
392mode. Cargo will restrict itself to crates that are downloaded locally, even
393if there might be a newer version as indicated in the local copy of the index.
394See the \fBcargo\-fetch\fP(1) command to download dependencies before going
395offline.
396.sp
397May also be specified with the \fBnet.offline\fP \c
398.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
399.RE
400.SS "Common Options"
401.sp
402\fB\-h\fP, \fB\-\-help\fP
403.RS 4
404Prints help information.
405.RE
406.sp
407\fB\-Z\fP \fIFLAG\fP...
408.RS 4
409Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for
410details.
411.RE
412.SS "Miscellaneous Options"
413.sp
414\fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP
415.RS 4
416Number of parallel jobs to run. May also be specified with the
417\fBbuild.jobs\fP \c
418.URL "https://doc.rust\-lang.org/cargo/reference/config.html" "config value" "."
419Defaults to
420the number of CPUs.
421.RE
422.SH "PROFILES"
423.sp
424Profiles may be used to configure compiler options such as optimization levels
425and debug settings. See
426\c
427.URL "https://doc.rust\-lang.org/cargo/reference/manifest.html#the\-profile\-sections" "the reference"
428for more details.
429.sp
430Profile selection depends on the target and crate being built. By default the
431\fBdev\fP or \fBtest\fP profiles are used. If the \fB\-\-release\fP flag is given, then the
432\fBrelease\fP or \fBbench\fP profiles are used.
433.TS
434allbox tab(:);
435lt lt lt.
436T{
437.sp
438Target
439T}:T{
440.sp
441Default Profile
442T}:T{
443.sp
444\fB\-\-release\fP Profile
445T}
446T{
447.sp
448lib, bin, example
449T}:T{
450.sp
451\fBdev\fP
452T}:T{
453.sp
454\fBrelease\fP
455T}
456T{
457.sp
458test, bench, or any target
459.br
460in "test" or "bench" mode
461T}:T{
462.sp
463\fBtest\fP
464T}:T{
465.sp
466\fBbench\fP
467T}
468.TE
469.sp
470.sp
471Dependencies use the \fBdev\fP/\fBrelease\fP profiles.
472.SH "ENVIRONMENT"
473.sp
474See \c
475.URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " "
476for
477details on environment variables that Cargo reads.
478.SH "EXIT STATUS"
479.sp
4800
481.RS 4
482Cargo succeeded.
483.RE
484.sp
485101
486.RS 4
487Cargo failed to complete.
488.RE
489.SH "EXAMPLES"
490.sp
491.RS 4
492.ie n \{\
493\h'-04' 1.\h'+01'\c
494.\}
495.el \{\
496. sp -1
497. IP " 1." 4.2
498.\}
499Apply compiler suggestions to the local package:
500.sp
501.if n .RS 4
502.nf
503cargo fix
504.fi
505.if n .RE
506.RE
507.sp
508.RS 4
509.ie n \{\
510\h'-04' 2.\h'+01'\c
511.\}
512.el \{\
513. sp -1
514. IP " 2." 4.2
515.\}
516Convert a 2015 edition to 2018:
517.sp
518.if n .RS 4
519.nf
520cargo fix \-\-edition
521.fi
522.if n .RE
523.RE
524.sp
525.RS 4
526.ie n \{\
527\h'-04' 3.\h'+01'\c
528.\}
529.el \{\
530. sp -1
531. IP " 3." 4.2
532.\}
533Apply suggested idioms for the current edition:
534.sp
535.if n .RS 4
536.nf
537cargo fix \-\-edition\-idioms
538.fi
539.if n .RE
540.RE
541.SH "SEE ALSO"
542.sp
543\fBcargo\fP(1), \fBcargo\-check\fP(1)