4 cargo-check — Check the current package
10 Check a local package and all of its dependencies for errors. This will
11 essentially compile the packages without performing the final step of
12 code generation, which is faster than running cargo build. The compiler
13 will save metadata files to disk so that future runs will reuse them if
14 the source has not been modified. Some diagnostics and errors are only
15 emitted during code generation, so they inherently won’t be reported
20 By default, when no package selection options are given, the packages
21 selected depend on the selected manifest file (based on the current
22 working directory if --manifest-path is not given). If the manifest is
23 the root of a workspace then the workspaces default members are
24 selected, otherwise only the package defined by the manifest will be
27 The default members of a workspace can be set explicitly with the
28 workspace.default-members key in the root manifest. If this is not set,
29 a virtual workspace will include all workspace members (equivalent to
30 passing --workspace), and a non-virtual workspace will include only the
33 -p spec…, --package spec…
34 Check only the specified packages. See cargo-pkgid(1) for the SPEC
35 format. This flag may be specified multiple times and supports
36 common Unix glob patterns like *, ? and []. However, to avoid your
37 shell accidentally expanding glob patterns before Cargo handles
38 them, you must use single quotes or double quotes around each
42 Check all members in the workspace.
45 Deprecated alias for --workspace.
48 Exclude the specified packages. Must be used in conjunction with the
49 --workspace flag. This flag may be specified multiple times and
50 supports common Unix glob patterns like *, ? and []. However, to
51 avoid your shell accidentally expanding glob patterns before Cargo
52 handles them, you must use single quotes or double quotes around
56 When no target selection options are given, cargo check will check all
57 binary and library targets of the selected packages. Binaries are
58 skipped if they have required-features that are missing.
60 Passing target selection flags will check only the specified targets.
62 Note that --bin, --example, --test and --bench flags also support common
63 Unix glob patterns like *, ? and []. However, to avoid your shell
64 accidentally expanding glob patterns before Cargo handles them, you must
65 use single quotes or double quotes around each glob pattern.
68 Check the package’s library.
71 Check the specified binary. This flag may be specified multiple
72 times and supports common Unix glob patterns.
75 Check all binary targets.
78 Check the specified example. This flag may be specified multiple
79 times and supports common Unix glob patterns.
82 Check all example targets.
85 Check the specified integration test. This flag may be specified
86 multiple times and supports common Unix glob patterns.
89 Check all targets in test mode that have the test = true manifest
90 flag set. By default this includes the library and binaries built as
91 unittests, and integration tests. Be aware that this will also build
92 any required dependencies, so the lib target may be built twice
93 (once as a unittest, and once as a dependency for binaries,
94 integration tests, etc.). Targets may be enabled or disabled by
95 setting the test flag in the manifest settings for the target.
98 Check the specified benchmark. This flag may be specified multiple
99 times and supports common Unix glob patterns.
102 Check all targets in benchmark mode that have the bench = true
103 manifest flag set. By default this includes the library and binaries
104 built as benchmarks, and bench targets. Be aware that this will also
105 build any required dependencies, so the lib target may be built
106 twice (once as a benchmark, and once as a dependency for binaries,
107 benchmarks, etc.). Targets may be enabled or disabled by setting the
108 bench flag in the manifest settings for the target.
111 Check all targets. This is equivalent to specifying --lib --bins
112 --tests --benches --examples.
115 The feature flags allow you to control which features are enabled. When
116 no feature options are given, the default feature is activated for every
119 See the features documentation
120 <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options>
123 -F features, --features features
124 Space or comma separated list of features to activate. Features of
125 workspace members may be enabled with package-name/feature-name
126 syntax. This flag may be specified multiple times, which enables all
130 Activate all available features of all selected packages.
132 --no-default-features
133 Do not activate the default feature of the selected packages.
137 Check for the given architecture. The default is the host
138 architecture. The general format of the triple is
139 <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for
140 a list of supported targets. This flag may be specified multiple
143 This may also be specified with the build.target config value
144 <https://doc.rust-lang.org/cargo/reference/config.html>.
146 Note that specifying this flag makes Cargo run in a different mode
147 where the target artifacts are placed in a separate directory. See
149 <https://doc.rust-lang.org/cargo/guide/build-cache.html>
150 documentation for more details.
153 Check optimized artifacts with the release profile. See also the
154 --profile option for choosing a specific profile by name.
157 Check with the given profile.
159 As a special case, specifying the test profile will also enable
160 checking in test mode which will enable checking tests and enable
161 the test cfg option. See rustc tests
162 <https://doc.rust-lang.org/rustc/tests/index.html> for more detail.
165 <https://doc.rust-lang.org/cargo/reference/profiles.html> for more
168 --ignore-rust-version
169 Check the target even if the selected Rust compiler is older than
170 the required Rust version as configured in the project’s
174 Output information how long each compilation takes, and track
175 concurrency information over time. Accepts an optional
176 comma-separated list of output formats; --timings without an
177 argument will default to --timings=html. Specifying an output format
178 (rather than the default) is unstable and requires
179 -Zunstable-options. Valid output formats:
181 o html (unstable, requires -Zunstable-options): Write a
182 human-readable file cargo-timing.html to the target/cargo-timings
183 directory with a report of the compilation. Also write a report
184 to the same directory with a timestamp in the filename if you
185 want to look at older runs. HTML output is suitable for human
186 consumption only, and does not provide machine-readable timing
189 o json (unstable, requires -Zunstable-options): Emit
190 machine-readable JSON information about timing information.
193 --target-dir directory
194 Directory for all generated artifacts and intermediate files. May
195 also be specified with the CARGO_TARGET_DIR environment variable, or
196 the build.target-dir config value
197 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
198 target in the root of the workspace.
202 Use verbose output. May be specified twice for “very verbose”
203 output which includes extra output such as dependency warnings and
204 build script output. May also be specified with the term.verbose
206 <https://doc.rust-lang.org/cargo/reference/config.html>.
209 Do not print cargo log messages. May also be specified with the
210 term.quiet config value
211 <https://doc.rust-lang.org/cargo/reference/config.html>.
214 Control when colored output is used. Valid values:
216 o auto (default): Automatically detect if color support is
217 available on the terminal.
219 o always: Always display colors.
221 o never: Never display colors.
223 May also be specified with the term.color config value
224 <https://doc.rust-lang.org/cargo/reference/config.html>.
227 The output format for diagnostic messages. Can be specified multiple
228 times and consists of comma-separated values. Valid values:
230 o human (default): Display in a human-readable text format.
231 Conflicts with short and json.
233 o short: Emit shorter, human-readable text messages. Conflicts with
236 o json: Emit JSON messages to stdout. See the reference
237 <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages>
238 for more details. Conflicts with human and short.
240 o json-diagnostic-short: Ensure the rendered field of JSON messages
241 contains the “short” rendering from rustc. Cannot be used
244 o json-diagnostic-rendered-ansi: Ensure the rendered field of JSON
245 messages contains embedded ANSI color codes for respecting
246 rustc’s default color scheme. Cannot be used with human or
249 o json-render-diagnostics: Instruct Cargo to not include rustc
250 diagnostics in JSON messages printed, but instead Cargo itself
251 should render the JSON diagnostics coming from rustc. Cargo’s
252 own JSON diagnostics and others coming from rustc are still
253 emitted. Cannot be used with human or short.
257 Path to the Cargo.toml file. By default, Cargo searches for the
258 Cargo.toml file in the current directory or any parent directory.
261 Either of these flags requires that the Cargo.lock file is
262 up-to-date. If the lock file is missing, or it needs to be updated,
263 Cargo will exit with an error. The --frozen flag also prevents Cargo
264 from attempting to access the network to determine if it is
267 These may be used in environments where you want to assert that the
268 Cargo.lock file is up-to-date (such as a CI build) or want to avoid
272 Prevents Cargo from accessing the network for any reason. Without
273 this flag, Cargo will stop with an error if it needs to access the
274 network and the network is not available. With this flag, Cargo will
275 attempt to proceed without the network if possible.
277 Beware that this may result in different dependency resolution than
278 online mode. Cargo will restrict itself to crates that are
279 downloaded locally, even if there might be a newer version as
280 indicated in the local copy of the index. See the cargo-fetch(1)
281 command to download dependencies before going offline.
283 May also be specified with the net.offline config value
284 <https://doc.rust-lang.org/cargo/reference/config.html>.
288 If Cargo has been installed with rustup, and the first argument to
289 cargo begins with +, it will be interpreted as a rustup toolchain
290 name (such as +stable or +nightly). See the rustup documentation
291 <https://rust-lang.github.io/rustup/overrides.html> for more
292 information about how toolchain overrides work.
294 --config KEY=VALUE or PATH
295 Overrides a Cargo configuration value. The argument should be in
296 TOML syntax of KEY=VALUE, or provided as a path to an extra
297 configuration file. This flag may be specified multiple times. See
298 the command-line overrides section
299 <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides>
300 for more information.
303 Changes the current working directory before executing any specified
304 operations. This affects things like where cargo looks by default
305 for the project manifest (Cargo.toml), as well as the directories
306 searched for discovering .cargo/config.toml, for example. This
307 option must appear before the command name, for example cargo -C
308 path/to/my-project build.
310 This option is only available on the nightly channel
311 <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
312 requires the -Z unstable-options flag to enable (see #10098
313 <https://github.com/rust-lang/cargo/issues/10098>).
316 Prints help information.
319 Unstable (nightly-only) flags to Cargo. Run cargo -Z help for
322 Miscellaneous Options
324 Number of parallel jobs to run. May also be specified with the
325 build.jobs config value
326 <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
327 the number of logical CPUs. If negative, it sets the maximum number
328 of parallel jobs to the number of logical CPUs plus provided value.
329 If a string default is provided, it sets the value back to defaults.
333 Build as many crates in the dependency graph as possible, rather
334 than aborting the build on the first one that fails to build.
336 For example if the current package depends on dependencies fails and
337 works, one of which fails to build, cargo check -j1 may or may not
338 build the one that succeeds (depending on which one of the two
339 builds Cargo picked to run first), whereas cargo check -j1
340 --keep-going would definitely run both builds, even if the one run
343 --future-incompat-report
344 Displays a future-incompat report for any future-incompatible
345 warnings produced during execution of this command
351 <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
352 for details on environment variables that Cargo reads.
355 o 0: Cargo succeeded.
357 o 101: Cargo failed to complete.
360 1. Check the local package for errors:
364 2. Check all targets, including unit tests:
366 cargo check --all-targets --profile=test
369 cargo(1), cargo-build(1)