How to determine the rust-version if MSRV depends on dev-dependencies

For example, if dev-dependencies requires Rust 1.82 or later, but others requires Rust 1.56 or later, is it better to specify the rust-version as 1.82 or as 1.56?

I know that dev-dependencies are not needed except when running tests, examples, and benchmarks, and are not needed when publishing to crates.io. So I think it would be better to specify 1.56 as the rust-version, but I think this might give the wrong impression that tests can also be run on Rust 1.56.

In such cases, which version should be specified for the rust-version?

Related topic:

The MSRV resolver RFC has the following to say about dev-dependencies:

In some cases, the MSRV-incompatible dependencies might be restricted to dev-dependencies. Though local development can’t be performed with the MSRV, the fact that the tests are verifying (on a newer toolchain) that the build/normal dependencies work gives a good amount of confidence that they will work on the MSRV so long as they compile.

I personally chose to interpret the supported term in MSRV for one of my projects as:

The MSRV will be chosen as the minimum version of rustc that can successfully pass CI, including documentation, lints, and all examples.

My MSRV policy goes on to clarify the distinction between the minimum version supported and required. Where the minimum required Rust version is what you are talking about with regard to exceptions for dev-dependencies and so on.

I also made an effort in CI to check both supported and required versions, but it's actually quite painful because Cargo doesn't have first-class support for making this distinction. It's a hack that kind of works most of the time.

This is in no way recommended. It's just what I settled on.

References:

I'd say ignore dev dependencies completely. Set MSRV to the lowest Rust version that can work in any configuration of your crate.

rust-version is mainly used when people add crates-io dependencies, and crates used as dependencies do not include any dev dependency crates.

If you set MSRV too high, then users of older Rust will be completely unable to use your crate, even if the code would be compatible. If you set MSRV too low, then it will work everywhere it can work, it will just give worse error message where it can't work anyway.

1 Like

In practice, MSRV is largely a policy concern and rust-version is a tooling concern. This is why I chose to make the distinction explicit in my policy. In case it isn't clear, rust-version <= MSRV.

In other words, I will provide support if you are building with at least 1.76, but the crate only requires and will work fine with 1.74.

Reasoning: The larger ecosystem of sibling crates may increase the rust-version beyond the baseline of my own dependency tree. It never decreases. Sibling crates are just as much "a part" of my crate as any of its direct and indirect dependencies.

If winit bumps their rust-version, that affects users of my crate even though my crate doesn't have any dependency on winit. It's just that winit is the most popular windowing crate to use with pixels. This is reflected in examples, mostly, but also doctests.

1 Like