CARGO-CHECK(1)

๐Ÿ“ฆ version 1.84.1, in ubuntu jammy, ubuntu noble

๐Ÿ’… CARGO-CHECK(1) โ€” the manual, but make it make sense

okay bestie, welcome to the manual page for cargo-check โ€” it lives in the General Commands Manual section, and it's genuinely one of the most useful little commands in the whole Cargo family. let's get into it ๐Ÿ’–


โœจ NAME โœจ

cargo-check โ€” check the current package ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

cargo check [options]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So here's the vibe: cargo check takes a local package and all of its dependencies and checks them for errors. The way it does that is by essentially compiling the packages without doing the final step of code generation โ€” which is exactly why it's faster than running cargo build. no cap, it's the speedrun version ๐Ÿ”ฅ

The compiler will save metadata files to disk, so future runs will just reuse them if the source hasn't been modified. efficiency queen behavior ๐Ÿ‘‘

but lowkey important: some diagnostics and errors are only emitted during code generation, so they inherently won't be reported with cargo check. it's giving "mostly the whole picture" not "literally the whole picture" ๐Ÿ˜ญ

๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

๐ŸŽ€ Package Selection

okay so by default, when you don't pass any package selection options, the packages selected depend on the selected manifest file (which is based on the current working directory if --manifest-path isn't given). If the manifest is the root of a workspace then the workspace's default members get selected โ€” otherwise only the package defined by the manifest gets selected.

The default members of a workspace can be set explicitly with the workspace.default-members key in the root manifest. If that's not set, then:

  • a virtual workspace will include all workspace members (equivalent to passing --workspace), and
  • a non-virtual workspace will include only the root crate itself.

  • -p specโ€ฆ, --package specโ€ฆ โ€” check only the specified packages. See cargo-pkgid(1) for the SPEC format. This flag may be specified multiple times and supports common Unix glob patterns like *, ? and []. however, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. (your shell is not the main character here, bestie ๐Ÿซถ)
  • --workspace โ€” check all members in the workspace. the whole squad ๐Ÿ’œ
  • --all โ€” deprecated alias for --workspace. it's giving legacy, we don't use it anymore ๐Ÿซ 
  • --exclude *SPEC*โ€ฆ โ€” exclude the specified packages. Must be used in conjunction with the --workspace flag. This flag may be specified multiple times and supports common Unix glob patterns like *, ? and []. however, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. not me excluding people from the group chat ๐Ÿ˜ญ

๐ŸŒˆ Target Selection

When no target selection options are given, cargo check will check all binary and library targets of the selected packages. Binaries are skipped if they have required-features that are missing. (sorry babes, no features no entry โœ‹)

Passing target selection flags will check only the specified targets.

heads up: --bin, --example, --test and --bench flags also support common Unix glob patterns like *, ? and []. However, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each glob pattern. ๐Ÿ’…

  • --lib โ€” check the package's library. the library, the icon, the moment โœจ
  • --bin *name*โ€ฆ โ€” check the specified binary. This flag may be specified multiple times and supports common Unix glob patterns.
  • --bins โ€” check all binary targets.
  • --example *name*โ€ฆ โ€” check the specified example. This flag may be specified multiple times and supports common Unix glob patterns.
  • --examples โ€” check all example targets.
  • --test *name*โ€ฆ โ€” check the specified integration test. This flag may be specified multiple times and supports common Unix glob patterns.
  • --tests โ€” check all targets that have the test = true manifest flag set. By default this includes the library and binaries built as unittests, and integration tests. be aware that this will also build any required dependencies, so the lib target may be built twice (once as a unittest, and once as a dependency for binaries, integration tests, etc.). Targets may be enabled or disabled by setting the test flag in the manifest settings for the target. double duty, she's booked and busy ๐Ÿ˜ฎโ€๐Ÿ’จ
  • --bench *name*โ€ฆ โ€” check the specified benchmark. This flag may be specified multiple times and supports common Unix glob patterns.
  • --benches โ€” check all targets that have the bench = true manifest flag set. By default this includes the library and binaries built as benchmarks, and bench targets. be aware that this will also build any required dependencies, so the lib target may be built twice (once as a benchmark, and once as a dependency for binaries, benchmarks, etc.). Targets may be enabled or disabled by setting the bench flag in the manifest settings for the target. again with the double build, she's doing overtime fr fr ๐Ÿ˜ญ
  • --all-targets โ€” check all targets. This is equivalent to specifying --lib --bins --tests --benches --examples. the full combo meal, ate and left no crumbs ๐Ÿ“

๐Ÿงš Feature Selection

The feature flags let you control which features are enabled. When no feature options are given, the default feature is activated for every selected package. (defaults are the blueprint, the rest is customization ๐Ÿ’…)

See the features documentation <https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options> for more details. iykyk ๐Ÿ“š


  • -F features, --features features โ€” space or comma separated list of features to activate. Features of workspace members may be enabled with package-name/feature-name syntax. This flag may be specified multiple times, which enables all specified features. stacking them like accessories, obsessed ๐Ÿ’œ
  • --all-features โ€” activate all available features of all selected packages. go big or go home โœจ
  • --no-default-features โ€” do not activate the default feature of the selected packages. sometimes you gotta say no to the default, boundaries are healthy ๐Ÿซถ

๐Ÿ’€ Compilation Options

  • --target triple โ€” check for the given architecture. The default is the host architecture. The general format of the triple is <arch><sub>-<vendor>-<sys>-<abi>. Run rustc --print target-list for a list of supported targets. This flag may be specified multiple times.

This may also be specified with the build.target config value <https://doc.rust-lang.org/cargo/reference/config.html>.

note: specifying this flag makes Cargo run in a different mode where the target artifacts are placed in a separate directory. See the build cache documentation <https://doc.rust-lang.org/cargo/reference/build-cache.html> for more details. different directory, different era ๐Ÿฆ‹
  • -r, --release โ€” check optimized artifacts with the release profile. See also the --profile option for choosing a specific profile by name. glow up mode ๐Ÿ”ฅ
  • --profile name โ€” check with the given profile.

As a special case, specifying the test profile will also enable checking in test mode, which will enable checking tests and enable the test cfg option. See rustc tests <https://doc.rust-lang.org/rustc/tests/index.html> for more detail.

See the reference <https://doc.rust-lang.org/cargo/reference/profiles.html> for more details on profiles.

  • --timings=fmts โ€” output information about how long each compilation takes, and track concurrency information over time. Accepts an optional comma-separated list of output formats; --timings without an argument will default to --timings=html. Specifying an output format (rather than the default) is unstable and requires -Zunstable-options. Valid output formats:
    • html (unstable, requires -Zunstable-options): write a human-readable file cargo-timing.html to the target/cargo-timings directory with a report of the compilation. Also write a report to the same directory with a timestamp in the filename if you want to look at older runs. HTML output is suitable for human consumption only, and does not provide machine-readable timing data. pretty report for the girlies ๐ŸŽ€
    • json (unstable, requires -Zunstable-options): emit machine-readable JSON information about timing information. for the robots ๐Ÿค–

๐ŸŒธ Output Options

  • --target-dir directory โ€” directory for all generated artifacts and intermediate files. May also be specified with the CARGO_TARGET_DIR environment variable, or the build.target-dir config value <https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to target in the root of the workspace. your stuff, your room, your rules ๐Ÿ’…

๐Ÿซถ Display Options

  • -v, --verbose โ€” use verbose output. May be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output. May also be specified with the term.verbose config value <https://doc.rust-lang.org/cargo/reference/config.html>. double it and give it to the next person ๐Ÿ—ฃ๏ธ
  • -q, --quiet โ€” do not print cargo log messages. May also be specified with the term.quiet config value <https://doc.rust-lang.org/cargo/reference/config.html>. silence, she's meditating ๐Ÿง˜
  • --color when โ€” control when colored output is used. Valid values:
    • auto (default): automatically detect if color support is available on the terminal.
    • always: always display colors. ๐ŸŒˆ
    • never: never display colors.

May also be specified with the term.color config value <https://doc.rust-lang.org/cargo/reference/config.html>.

  • --message-format fmt โ€” the output format for diagnostic messages. Can be specified multiple times and consists of comma-separated values. Valid values:
    • human (default): display in a human-readable text format. Conflicts with short and json.
    • short: emit shorter, human-readable text messages. Conflicts with human and json.
    • json: emit JSON messages to stdout. See the reference <https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages> for more details. Conflicts with human and short.
    • json-diagnostic-short: ensure the rendered field of JSON messages contains the "short" rendering from rustc. Cannot be used with human or short.
    • json-diagnostic-rendered-ansi: ensure the rendered field of JSON messages contains embedded ANSI color codes for respecting rustc's default color scheme. Cannot be used with human or short.
    • json-render-diagnostics: instruct Cargo to not include rustc diagnostics in JSON messages printed, but instead Cargo itself should render the JSON diagnostics coming from rustc. Cargo's own JSON diagnostics and others coming from rustc are still emitted. Cannot be used with human or short.

โญ Manifest Options

  • --manifest-path path โ€” path to the Cargo.toml file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory. it will find it, she always finds it ๐Ÿ”
  • --ignore-rust-version โ€” ignore rust-version specification in packages. respectfully, we're ignoring that ๐Ÿ™ˆ
  • --locked โ€” asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file was originally generated. Cargo will exit with an error when either of the following scenarios arises:
    • The lock file is missing.
    • Cargo attempted to change the lock file due to a different dependency resolution.
no wiggle room on this one bestie. --locked means locked, fr fr ๐Ÿ”’

...and like, that's literally the whole point: you can use it in environments where you want deterministic builds, like CI pipelines and stuff. ๐ŸŽ€


โœจ OPTIONS (the rest of them, bestie) โœจ

  • --offline โ€” no internet, no problem, kinda. This one stops Cargo from touching the network for any reason whatsoever. Without the flag, if Cargo needs the network and the network is being flaky or just isn't there, it gives up and errors out. With the flag? Cargo tries its best to keep going without the network if that's even possible. ๐Ÿซถ
โš ๏ธ Lowkey important: this can give you different dependency resolution than online mode does. Cargo restricts itself to crates that are already downloaded locally โ€” even if there's a newer version hanging out in your local copy of the index. So like, you might not get what you'd get online. Not a bug, just how it is, bestie.

Wanna do it properly? Peep cargo-fetch(1) to download your dependencies before you go offline. ๐ŸŒธ

You can also set this with the net.offline config value <https://doc.rust-lang.org/cargo/reference/config.html>.

  • --frozen โ€” this is just --locked and --offline at the same time. Two-for-one, no notes. ๐Ÿ’…
  • --lockfile-path PATH โ€” okay so this changes where the lockfile lives. Instead of the default (<workspace_root>/Cargo.lock), it goes to PATH. And PATH has to end with Cargo.lock โ€” like --lockfile-path /tmp/temporary-lockfile/Cargo.lock, for example. ๐Ÿ“

The tea here: giving --lockfile-path makes Cargo ignore whatever existing lockfile is at the default path. Instead it'll either use the lockfile from PATH, or write a brand-new lockfile into the PATH you gave it if there isn't one already. Slay.

Why would you want that? So you can run most commands in read-only directories and just write the lockfile into the PATH you provided. Genius, honestly. ๐Ÿง 

๐Ÿ™ˆ Heads up: this option is only available on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and it needs the -Z unstable-options flag to turn on (see #14421 <https://github.com/rust-lang/cargo/issues/14421>).

๐ŸŒˆ Common Options ๐ŸŒˆ

  • +toolchain โ€” if Cargo got installed via rustup and the very first argument to cargo starts with +, it gets read as a rustup toolchain name. So like +stable or +nightly, you know? The rustup docs <https://rust-lang.github.io/rustup/overrides.html> have more on how toolchain overrides work if you wanna go deep. ๐Ÿฆ‹
  • --config KEY=VALUE or PATH โ€” overrides a Cargo config value, periodt. The argument should be TOML syntax like KEY=VALUE, or you can hand it a path to an extra config file instead. You can use this flag multiple times โ€” stack 'em up, queen. ๐Ÿ‘‘ Check the command-line overrides section <https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides> for the deets.
  • -C PATH โ€” changes the current working directory before Cargo does any of the operations you asked for. This affects stuff like where Cargo looks by default for the project manifest (Cargo.toml), and also which directories get searched when discovering .cargo/config.toml. Ngl it's giving "run this from over there". โœจ
๐Ÿ’€ Important: this option has to come before the command name. Like cargo -C path/to/my-project build. Not after. Do not.

Also, this one's only on the nightly channel <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and needs -Z unstable-options to enable it (see #10098 <https://github.com/rust-lang/cargo/issues/10098>).

  • -h, --help โ€” prints help information. When in doubt, ask for help, bestie. That's growth. ๐ŸŒฑ
  • -Z flag โ€” unstable (nightly-only) flags for Cargo. Run cargo -Z help for the details. The forbidden knowledge section, iykyk. ๐Ÿ”ฅ

๐ŸŽ€ Miscellaneous Options ๐ŸŽ€

Okay the math bit: if the number is negative, it sets the max number of parallel jobs to the number of logical CPUs plus the value you gave. And if you pass a string default, it sets the value back to the defaults. It should not be 0 โ€” do not do that. ๐Ÿšซ

  • --keep-going โ€” builds as many crates in the dependency graph as it possibly can instead of bailing out the second one fails. Main character energy: finish the run. ๐Ÿ’ช

Example time, 'cause this one's easier with an example: say your current package depends on two dependencies, and one of them fails to build while the other works. Then cargo check -j1 might build the one that succeeds, or it might not โ€” depends on which of the two Cargo decided to run first, kinda random honestly. But cargo check -j1 --keep-going would definitely run both builds, even if the first one it ran fails. ๐ŸŒŸ

  • --future-incompat-report โ€” shows you a future-incompat report for any future-incompatible warnings that popped up while this command was running. Crystal ball vibes. ๐Ÿ”ฎ

See cargo-report(1).


๐ŸŒ ENVIRONMENT ๐ŸŒ

Cargo reads some environment variables, bestie. The reference <https://doc.rust-lang.org/cargo/reference/environment-variables.html> has all the details on which ones.


๐Ÿšฆ EXIT STATUS ๐Ÿšฆ

  • 0: Cargo succeeded. ๐ŸŽ‰ we ate.
  • 101: Cargo failed to complete. ๐Ÿ˜ญ it's not giving.

๐Ÿ’– EXAMPLES ๐Ÿ’–

  1. Check the local package for errors:
cargo check
  1. Check all targets, including unit tests:
cargo check --all-targets --profile=test

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

cargo(1), cargo-build(1)


okay that's the whole page, bestie!! this was the cargo-check(1) manual page from the Cargo docs, and it's dated April 2025. go forth and check your crates ๐Ÿ’…โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from