Rust crate users need to know which compiler release a package still supports before they upgrade dependencies or run continuous integration against older environments. Cargo stores that compatibility boundary in the package manifest so an unsupported compiler fails early with a clear version error.
The manifest key is rust-version in the Cargo.toml package table. Its value is a bare Rust version such as 1.70, not a semver range, toolchain channel, nightly name, or dependency requirement.
Set the value to the oldest Rust release the crate is actually tested with. If the crate uses a newer edition, standard-library API, dependency version, or compiler feature, raise the MSRV or change the code before publishing that compatibility promise.
Steps to set a Rust MSRV in Cargo:
- Open a terminal in the package directory that contains Cargo.toml.
For a workspace, set rust-version in each member package that needs an explicit compatibility policy.
- Add rust-version to the package table.
- Cargo.toml
[package] name = "demo-lib" version = "0.1.0" edition = "2021" rust-version = "1.70" [dependencies]
Use a bare version number with at least one component. Values such as >=1.70, 1.70-nightly, or stable are not valid rust-version values.
- Install the MSRV toolchain if it is not already installed.
$ rustup toolchain install 1.70.0 --profile minimal
Use the patch version that matches the MSRV line being tested. The manifest may use 1.70 while rustup installs the release as 1.70.0.
- Check the package with the MSRV toolchain.
$ cargo +1.70.0 check --all-targets Checking demo-lib v0.1.0 (/work/demo-lib) Finished dev [unoptimized + debuginfo] target(s) in 0.18s--all-targets includes library, binary, test, bench, and example targets selected by Cargo. Add the same feature flags used by your crate's supported configuration, such as --all-features when every feature must support the MSRV.
Related: How to check Rust code with Cargo
- Install one older toolchain when the version boundary needs a failure check.
$ rustup toolchain install 1.69.0 --profile minimal
Skip this probe when the MSRV check is enough for the change review, or replace 1.69.0 with the immediately older Rust release for your chosen MSRV.
- Confirm Cargo rejects the older compiler.
$ cargo +1.69.0 check --all-targets error: package `demo-lib v0.1.0 (/work/demo-lib)` cannot be built because it requires rustc 1.70 or newer, while the currently active rustc version is 1.69.0
Do not use --ignore-rust-version in an MSRV check. That option bypasses the manifest guard and is only useful when intentionally testing an unsupported build.
- Run the project test suite with the MSRV toolchain before release or CI handoff.
$ cargo +1.70.0 test --all-targets Compiling demo-lib v0.1.0 (/work/demo-lib) Finished test [unoptimized + debuginfo] target(s) in 0.20s Running unittests src/lib.rs (target/debug/deps/demo_lib-e2b4119928f07e2e) running 1 test test tests::it_works ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00sA cargo check pass proves the manifest boundary and type-checks selected targets. A test run catches code paths that only execute under the crate's tests.
Related: How to run Rust tests with Cargo
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.