cargo Verified current stable Not installed? Programming

Cargo / Check With Features

Check With Features

Checks the current package with specified features enabled to test conditional code paths.

$
Terminal
cargo c -F <feature1,feature2>

When To Use

When developing features that conditionally change application logic, ensuring all paths compile when all specified features are enabled.

Pro Tip

Consider adding `--all-features` for a comprehensive check of the package’s capabilities when multiple features are involved.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Checking for the following features:

 feature1      : enabled
 feature2      : enabled

 Finished dev [unoptimized + debuginfo] target(s) in 0.20s

Anatomy of Output

Understanding the result

Checking `my_package` with features `feature1, feature2`... INFO

Shows which features are activated for the check.

Finished dev [unoptimized + debuginfo] target(s) in 0.30s BUILD STATUS

Status and duration of the check.

error: unresolved import `std::non_existent` ERROR

Points out issues attributed to at least one of the activated features.

Power User Variants

Optimized versions

cargo check --features feature1

Check with a single feature enabled.

cargo check --features feature1,feature2 --release

Check with multiple features enabled in release mode.

Troubleshooting

Common pitfalls

error: missing feature `non_existent_feature`

Solution: Check `Cargo.toml` for the correct spelling of the features.

error: feature `feature1` cannot be disabled at this point

Solution: Ensure you only enable features that are compatible with each other.

warning: type errors due to generic constraints in feature activation

Solution: Adjust type parameters to align with active features.

Command Breakdown

What each part is doing

cargo
Base Command
The executable that performs this operation. Here it runs Cargo before the shell applies any redirect operators.
c
c|check
The value supplied for c|check.
-F
F| features
The value supplied for F| features.
<feature1,feature2>
feature1,feature2
The value supplied for feature1,feature2.
-F
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run: cargo check --features feature1,feature2

  2. Step 2

    Verify: Ensure Cargo displays enabled features in the output.

Alternative Approaches

Comparable commands in other tools

Alternative programming tools for the same job.