standback 0.3.1

New standard library, old compiler.
Documentation
use version_check::{Channel, Version};

// We assume that features are never stabilized in patch versions.
// If a "Rust 2.0" is ever released, we'll have to handle that explicitly.
const MSRV_MINOR: u16 = 36;

fn main() {
    let msrv = Version::from_mmp(1, MSRV_MINOR, 0);

    let mut minor_used = match Version::read() {
        Some(version) => version,
        None => {
            println!(
                "cargo:warning=Unable to determine rustc version. Assuming rustc {}.",
                msrv
            );
            msrv
        }
    }
    .to_mmp()
    .1;

    // Treat as the stable release, even if not on it.
    let channel = Channel::read();
    match channel {
        Some(channel) if channel.is_beta() => minor_used -= 1,
        Some(channel) if channel.supports_features() => minor_used -= 2,
        _ => {}
    }

    // Eager macro expansion would be nice!
    macro_rules! old_stable_compilers {
        ($($msrv_str:literal $minor:literal),+,) => {$(
            if cfg!(feature = $msrv_str) {
                if $minor + 1 <= minor_used {
                    println!(r#"cargo:rustc-cfg=reexport="1.{}""#, $minor + 1);
                } else {
                    println!(r#"cargo:rustc-cfg=shim="1.{}""#, $minor + 1);
                }
            }
        )*};
    }

    // There's no need to include the most recent release of the stable compiler here.
    old_stable_compilers![
        "msrv-1-36" 36,
        "msrv-1-37" 37,
        "msrv-1-38" 38,
        "msrv-1-39" 39,
        "msrv-1-40" 40,
        "msrv-1-41" 41,
        "msrv-1-42" 42,
        "msrv-1-43" 43,
        "msrv-1-44" 44,
        "msrv-1-45" 45,
        "msrv-1-46" 46,
        "msrv-1-47" 47,
        "msrv-1-48" 48,
        "msrv-1-49" 49,
        "msrv-1-50" 50,
    ];
}