Matthew Maurer | bd39854 | 2019-09-05 16:25:08 -0700 | [diff] [blame] | 1 | '\" 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" |
| 31 | cargo\-fix \- Automatically fix lint warnings reported by rustc |
| 32 | .SH "SYNOPSIS" |
| 33 | .sp |
| 34 | \fBcargo fix [\fIOPTIONS\fP]\fP |
| 35 | .SH "DESCRIPTION" |
| 36 | .sp |
| 37 | This Cargo subcommand will automatically take rustc\(cqs suggestions from |
| 38 | diagnostics like warnings and apply them to your source code. This is intended |
| 39 | to help automate tasks that rustc itself already knows how to tell you to fix! |
| 40 | The \fBcargo fix\fP subcommand is also being developed for the Rust 2018 edition |
| 41 | to provide code the ability to easily opt\-in to the new edition without having |
| 42 | to worry about any breakage. |
| 43 | .sp |
| 44 | Executing \fBcargo fix\fP will under the hood execute \fBcargo\-check\fP(1). Any warnings |
| 45 | applicable to your crate will be automatically fixed (if possible) and all |
| 46 | remaining warnings will be displayed when the check process is finished. For |
| 47 | example if you\(cqd like to prepare for the 2018 edition, you can do so by |
| 48 | executing: |
| 49 | .sp |
| 50 | .if n .RS 4 |
| 51 | .nf |
| 52 | cargo fix \-\-edition |
| 53 | .fi |
| 54 | .if n .RE |
| 55 | .sp |
| 56 | which behaves the same as \fBcargo check \-\-all\-targets\fP. Similarly if you\(cqd like |
| 57 | to fix code for different platforms you can do: |
| 58 | .sp |
| 59 | .if n .RS 4 |
| 60 | .nf |
| 61 | cargo fix \-\-edition \-\-target x86_64\-pc\-windows\-gnu |
| 62 | .fi |
| 63 | .if n .RE |
| 64 | .sp |
| 65 | or if your crate has optional features: |
| 66 | .sp |
| 67 | .if n .RS 4 |
| 68 | .nf |
| 69 | cargo fix \-\-edition \-\-no\-default\-features \-\-features foo |
| 70 | .fi |
| 71 | .if n .RE |
| 72 | .sp |
| 73 | If you encounter any problems with \fBcargo fix\fP or otherwise have any questions |
| 74 | or 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 |
| 81 | Fix code even if it already has compiler errors. This is useful if \fBcargo |
| 82 | fix\fP fails to apply the changes. It will apply the changes and leave the |
| 83 | broken code in the working directory for you to inspect and manually fix. |
| 84 | .RE |
| 85 | .sp |
| 86 | \fB\-\-edition\fP |
| 87 | .RS 4 |
| 88 | Apply changes that will update the code to the latest edition. This will |
| 89 | not update the edition in the \fBCargo.toml\fP manifest, which must be updated |
| 90 | manually. |
| 91 | .RE |
| 92 | .sp |
| 93 | \fB\-\-edition\-idioms\fP |
| 94 | .RS 4 |
| 95 | Apply suggestions that will update code to the preferred style for the |
| 96 | current edition. |
| 97 | .RE |
| 98 | .sp |
| 99 | \fB\-\-allow\-no\-vcs\fP |
| 100 | .RS 4 |
| 101 | Fix code even if a VCS was not detected. |
| 102 | .RE |
| 103 | .sp |
| 104 | \fB\-\-allow\-dirty\fP |
| 105 | .RS 4 |
| 106 | Fix code even if the working directory has changes. |
| 107 | .RE |
| 108 | .sp |
| 109 | \fB\-\-allow\-staged\fP |
| 110 | .RS 4 |
| 111 | Fix code even if the working directory has staged changes. |
| 112 | .RE |
| 113 | .SS "Package Selection" |
| 114 | .sp |
| 115 | By default, when no package selection options are given, the packages selected |
| 116 | depend on the current working directory. In the root of a virtual workspace, |
| 117 | all workspace members are selected (\fB\-\-all\fP is implied). Otherwise, only the |
| 118 | package in the current directory will be selected. The default packages may be |
| 119 | overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP |
| 120 | manifest. |
| 121 | .sp |
| 122 | \fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP... |
| 123 | .RS 4 |
| 124 | Fix only the specified packages. See \fBcargo\-pkgid\fP(1) for the |
| 125 | SPEC format. This flag may be specified multiple times. |
| 126 | .RE |
| 127 | .sp |
| 128 | \fB\-\-all\fP |
| 129 | .RS 4 |
| 130 | Fix all members in the workspace. |
| 131 | .RE |
| 132 | .sp |
| 133 | \fB\-\-exclude\fP \fISPEC\fP... |
| 134 | .RS 4 |
| 135 | Exclude 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 |
| 140 | When 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 |
| 144 | Passing target selection flags will fix only the |
| 145 | specified targets. |
| 146 | .sp |
| 147 | \fB\-\-lib\fP |
| 148 | .RS 4 |
| 149 | Fix the package\(cqs library. |
| 150 | .RE |
| 151 | .sp |
| 152 | \fB\-\-bin\fP \fINAME\fP... |
| 153 | .RS 4 |
| 154 | Fix the specified binary. This flag may be specified multiple times. |
| 155 | .RE |
| 156 | .sp |
| 157 | \fB\-\-bins\fP |
| 158 | .RS 4 |
| 159 | Fix all binary targets. |
| 160 | .RE |
| 161 | .sp |
| 162 | \fB\-\-example\fP \fINAME\fP... |
| 163 | .RS 4 |
| 164 | Fix the specified example. This flag may be specified multiple times. |
| 165 | .RE |
| 166 | .sp |
| 167 | \fB\-\-examples\fP |
| 168 | .RS 4 |
| 169 | Fix all example targets. |
| 170 | .RE |
| 171 | .sp |
| 172 | \fB\-\-test\fP \fINAME\fP... |
| 173 | .RS 4 |
| 174 | Fix the specified integration test. This flag may be specified multiple |
| 175 | times. |
| 176 | .RE |
| 177 | .sp |
| 178 | \fB\-\-tests\fP |
| 179 | .RS 4 |
| 180 | Fix all targets in test mode that have the \fBtest = true\fP manifest |
| 181 | flag set. By default this includes the library and binaries built as |
| 182 | unittests, and integration tests. Be aware that this will also build any |
| 183 | required dependencies, so the lib target may be built twice (once as a |
| 184 | unittest, and once as a dependency for binaries, integration tests, etc.). |
| 185 | Targets may be enabled or disabled by setting the \fBtest\fP flag in the |
| 186 | manifest settings for the target. |
| 187 | .RE |
| 188 | .sp |
| 189 | \fB\-\-bench\fP \fINAME\fP... |
| 190 | .RS 4 |
| 191 | Fix the specified benchmark. This flag may be specified multiple times. |
| 192 | .RE |
| 193 | .sp |
| 194 | \fB\-\-benches\fP |
| 195 | .RS 4 |
| 196 | Fix all targets in benchmark mode that have the \fBbench = true\fP |
| 197 | manifest flag set. By default this includes the library and binaries built |
| 198 | as benchmarks, and bench targets. Be aware that this will also build any |
| 199 | required dependencies, so the lib target may be built twice (once as a |
| 200 | benchmark, and once as a dependency for binaries, benchmarks, etc.). |
| 201 | Targets may be enabled or disabled by setting the \fBbench\fP flag in the |
| 202 | manifest settings for the target. |
| 203 | .RE |
| 204 | .sp |
| 205 | \fB\-\-all\-targets\fP |
| 206 | .RS 4 |
| 207 | Fix all targets. This is equivalent to specifying \fB\-\-lib \-\-bins |
| 208 | \-\-tests \-\-benches \-\-examples\fP. |
| 209 | .RE |
| 210 | .SS "Feature Selection" |
| 211 | .sp |
| 212 | When no feature options are given, the \fBdefault\fP feature is activated for |
| 213 | every selected package. |
| 214 | .sp |
| 215 | \fB\-\-features\fP \fIFEATURES\fP |
| 216 | .RS 4 |
| 217 | Space or comma separated list of features to activate. These features only |
| 218 | apply to the current directory\(cqs package. Features of direct dependencies |
| 219 | may be enabled with \fB<dep\-name>/<feature\-name>\fP syntax. |
| 220 | .RE |
| 221 | .sp |
| 222 | \fB\-\-all\-features\fP |
| 223 | .RS 4 |
| 224 | Activate all available features of all selected packages. |
| 225 | .RE |
| 226 | .sp |
| 227 | \fB\-\-no\-default\-features\fP |
| 228 | .RS 4 |
| 229 | Do not activate the \fBdefault\fP feature of the current directory\(cqs |
| 230 | package. |
| 231 | .RE |
| 232 | .SS "Compilation Options" |
| 233 | .sp |
| 234 | \fB\-\-target\fP \fITRIPLE\fP |
| 235 | .RS 4 |
| 236 | Fix for the given architecture. The default is the host |
| 237 | architecture. The general format of the triple is |
| 238 | \fB<arch><sub>\-<vendor>\-<sys>\-<abi>\fP. Run \fBrustc \-\-print target\-list\fP for a |
| 239 | list of supported targets. |
| 240 | .sp |
| 241 | This 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 |
| 247 | Fix optimized artifacts with the \fBrelease\fP profile. See the |
| 248 | PROFILES section for details on how this affects profile selection. |
| 249 | .RE |
| 250 | .sp |
| 251 | \fB\-\-profile\fP \fINAME\fP |
| 252 | .RS 4 |
| 253 | Changes fix behavior. Currently only \fBtest\fP is |
| 254 | supported, which will fix with the |
| 255 | \fB#[cfg(test)]\fP attribute enabled. This is useful to have it |
| 256 | fix unit tests which are usually excluded via |
| 257 | the \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 |
| 263 | Directory for all generated artifacts and intermediate files. May also be |
| 264 | specified 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" "." |
| 267 | Defaults |
| 268 | to \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 |
| 274 | Use verbose output. May be specified twice for "very verbose" output which |
| 275 | includes extra output such as dependency warnings and build script output. |
| 276 | May 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 |
| 282 | No output printed to stdout. |
| 283 | .RE |
| 284 | .sp |
| 285 | \fB\-\-color\fP \fIWHEN\fP |
| 286 | .RS 4 |
| 287 | Control 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 |
| 298 | terminal. |
| 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 |
| 323 | May 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 |
| 329 | The 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 |
| 368 | Path to the \fBCargo.toml\fP file. By default, Cargo searches in the current |
| 369 | directory or any parent directory for the \fBCargo.toml\fP file. |
| 370 | .RE |
| 371 | .sp |
| 372 | \fB\-\-frozen\fP, \fB\-\-locked\fP |
| 373 | .RS 4 |
| 374 | Either of these flags requires that the \fBCargo.lock\fP file is |
| 375 | up\-to\-date. If the lock file is missing, or it needs to be updated, Cargo will |
| 376 | exit with an error. The \fB\-\-frozen\fP flag also prevents Cargo from |
| 377 | attempting to access the network to determine if it is out\-of\-date. |
| 378 | .sp |
| 379 | These 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 |
| 381 | access. |
| 382 | .RE |
| 383 | .sp |
| 384 | \fB\-\-offline\fP |
| 385 | .RS 4 |
| 386 | Prevents Cargo from accessing the network for any reason. Without this |
| 387 | flag, Cargo will stop with an error if it needs to access the network and |
| 388 | the network is not available. With this flag, Cargo will attempt to |
| 389 | proceed without the network if possible. |
| 390 | .sp |
| 391 | Beware that this may result in different dependency resolution than online |
| 392 | mode. Cargo will restrict itself to crates that are downloaded locally, even |
| 393 | if there might be a newer version as indicated in the local copy of the index. |
| 394 | See the \fBcargo\-fetch\fP(1) command to download dependencies before going |
| 395 | offline. |
| 396 | .sp |
| 397 | May 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 |
| 404 | Prints help information. |
| 405 | .RE |
| 406 | .sp |
| 407 | \fB\-Z\fP \fIFLAG\fP... |
| 408 | .RS 4 |
| 409 | Unstable (nightly\-only) flags to Cargo. Run \fBcargo \-Z help\fP for |
| 410 | details. |
| 411 | .RE |
| 412 | .SS "Miscellaneous Options" |
| 413 | .sp |
| 414 | \fB\-j\fP \fIN\fP, \fB\-\-jobs\fP \fIN\fP |
| 415 | .RS 4 |
| 416 | Number 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" "." |
| 419 | Defaults to |
| 420 | the number of CPUs. |
| 421 | .RE |
| 422 | .SH "PROFILES" |
| 423 | .sp |
| 424 | Profiles may be used to configure compiler options such as optimization levels |
| 425 | and debug settings. See |
| 426 | \c |
| 427 | .URL "https://doc.rust\-lang.org/cargo/reference/manifest.html#the\-profile\-sections" "the reference" |
| 428 | for more details. |
| 429 | .sp |
| 430 | Profile 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 |
| 434 | allbox tab(:); |
| 435 | lt lt lt. |
| 436 | T{ |
| 437 | .sp |
| 438 | Target |
| 439 | T}:T{ |
| 440 | .sp |
| 441 | Default Profile |
| 442 | T}:T{ |
| 443 | .sp |
| 444 | \fB\-\-release\fP Profile |
| 445 | T} |
| 446 | T{ |
| 447 | .sp |
| 448 | lib, bin, example |
| 449 | T}:T{ |
| 450 | .sp |
| 451 | \fBdev\fP |
| 452 | T}:T{ |
| 453 | .sp |
| 454 | \fBrelease\fP |
| 455 | T} |
| 456 | T{ |
| 457 | .sp |
| 458 | test, bench, or any target |
| 459 | .br |
| 460 | in "test" or "bench" mode |
| 461 | T}:T{ |
| 462 | .sp |
| 463 | \fBtest\fP |
| 464 | T}:T{ |
| 465 | .sp |
| 466 | \fBbench\fP |
| 467 | T} |
| 468 | .TE |
| 469 | .sp |
| 470 | .sp |
| 471 | Dependencies use the \fBdev\fP/\fBrelease\fP profiles. |
| 472 | .SH "ENVIRONMENT" |
| 473 | .sp |
| 474 | See \c |
| 475 | .URL "https://doc.rust\-lang.org/cargo/reference/environment\-variables.html" "the reference" " " |
| 476 | for |
| 477 | details on environment variables that Cargo reads. |
| 478 | .SH "EXIT STATUS" |
| 479 | .sp |
| 480 | 0 |
| 481 | .RS 4 |
| 482 | Cargo succeeded. |
| 483 | .RE |
| 484 | .sp |
| 485 | 101 |
| 486 | .RS 4 |
| 487 | Cargo 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 | .\} |
| 499 | Apply compiler suggestions to the local package: |
| 500 | .sp |
| 501 | .if n .RS 4 |
| 502 | .nf |
| 503 | cargo 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 | .\} |
| 516 | Convert a 2015 edition to 2018: |
| 517 | .sp |
| 518 | .if n .RS 4 |
| 519 | .nf |
| 520 | cargo 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 | .\} |
| 533 | Apply suggested idioms for the current edition: |
| 534 | .sp |
| 535 | .if n .RS 4 |
| 536 | .nf |
| 537 | cargo 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) |