What's the automated way to find out minimum required rust version with cargo?

I need some way to automatically have cargo give me an estimated minimum required rust version so that I can put that into Cargo.toml under [package] as rust-version=

I imagine you run some cargo command in your project and behind the scenes it expands all macros(but still tracks the original ones) and then makes a list of all unique identifiers and those from std lib, at least, are checked if they've attributes that say in which rust version they were introduced... and the highest one encountered from those is probably the (estimated) MSRV.

example:

#[stable(feature = "raw_ref_macros", since = "1.51.0")]
#[rustc_macro_transparency = "semitransparent"]
#[allow_internal_unstable(raw_ref_op)]
pub macro addr_of($place:expr) {
    &raw const $place
}

That would mean 1.51.0 is required just because I'm using addr_of! macro.

I see lib.rs site somehow is able to guess MSRV for crates with this note:

Minimum Supported Rust Version (MSRV) is only approximate. A range of two versions means "oldest rustc verified to work ~ oldest rustc that might work". Actual MSRV will vary depending on crate features, target platform, and dependency versions. The data is estimated based on the latest stable Rust version available at the time the crate has been published and cargo check or cargo clippy on Linux/aarch64.

example: All releases of ncurses // Lib.rs

GitHub - foresterre/cargo-msrv: 🦀 Find the minimum supported Rust version (MSRV) for your project maybe? (haven't used it myself yet)

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.