Call for testing: unstable Cargo support for `rust-version`

RFC 2495 specifies how crates can describe in their Cargo.toml what the minimal supported Rust version is.

While this will not be used during dependency resolution (that was scoped out of the RFC as future work), it can help give better error messages if you're trying to compile a crate with a compiler that is too old: instead of specific errors about APIs that are not available, you'll get an explicit error saying the compiler is not supported. There are also some nice potential wins for Clippy (which could figure out from the stated rust-version which lints should be applied) or for CI systems, that could automatically figure out which Rust version to run against to test MSRV support.

In order to test it, you will need nightly Cargo, and add the following to your Cargo.toml:

cargo-features = ["rust-version"]

[package]
rust-version = "1.54"

Then, run cargo +nightly c, and an error should appear:

error: package `foo v0.1.0 (/Users/djc/src/foo)` cannot be built because it
requires rustc 1.54 or newer, while the currently active rustc version is
1.53.0-nightly

I'm very interested to hear if the feature makes sense, if more documentation is needed, and if you see unexpected edge cases when for example testing with patched dependencies, path dependencies, git dependencies, in workspaces, with alternate registries, or anything else you can think of.

15 Likes

I'm here because I'm looking for the feature, I'm pleased to see that it's on its way.

My use-case being that I'm building my project in different environments, and it's not clear to me what my MRSV actually is -- I know it's newer than the one provided today in Debian Stable or by repl.it, because at least one of my dependencies fails to compile, but not how much newer. If my dependencies exposed their MSRV then I should be able to work out whether a shiny dependency is worth the higher MSRV.

Something (slightly off-topic) that I'd find helpful here is a version of cargo-bisect-rustc that works the other way around, to discover the real MSRV.

This probably won't see any usage until it's actually shipped. Addition of rust-version is in itself a breaking change that is currently incompatible with all Rust versions, so it's too impractical to use with crates on crates.io.

Please just ship it, the sooner the better!

5 Likes

Will do.

3 Likes

I've written up some documentation. All feedback welcome in the PR!

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.