Skip to content

Commit

Permalink
simplify and fixup check for nightly Rust
Browse files Browse the repository at this point in the history
The try_reserve_2 feature is enabled on stable and beta Rust 1.63, and
nightly Rust 1.64 and above.
  • Loading branch information
sunshowers committed Aug 12, 2022
1 parent ed3afac commit d53134e
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ fn main() {
if compiler.minor >= 56 {
println!("cargo:rustc-cfg=shrink_to");
}
if compiler.minor >= 63
&& (!compiler.beta || compiler.minor >= 64)
&& (!compiler.nightly || compiler.minor >= 65)
// Stable and beta 1.63 have a stable try_reserve_2.
if (compiler.minor >= 63
&& (compiler.channel == ReleaseChannel::Stable || compiler.channel == ReleaseChannel::Beta))
|| compiler.minor >= 64
{
println!("cargo:rustc-cfg=try_reserve_2");
}
}

struct Compiler {
minor: u32,
beta: bool,
nightly: bool,
channel: ReleaseChannel,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum ReleaseChannel {
Stable,
Beta,
Nightly,
}

fn rustc_version() -> Option<Compiler> {
Expand All @@ -47,11 +54,12 @@ fn rustc_version() -> Option<Compiler> {
return None;
}
let minor = pieces.next()?.parse().ok()?;
let beta = version.contains("beta");
let nightly = version.contains("nightly");
Some(Compiler {
minor,
beta,
nightly,
})
let channel = if version.contains("nightly") {
ReleaseChannel::Nightly
} else if version.contains("beta") {
ReleaseChannel::Beta
} else {
ReleaseChannel::Stable
};
Some(Compiler { minor, channel })
}

0 comments on commit d53134e

Please sign in to comment.