Skip to content

Commit

Permalink
Restrict when try_reserve_2 is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius authored and sunshowers committed Aug 12, 2022
1 parent 43ec619 commit ed3afac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ jobs:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
# 1.34 is the MSRV, and the other versions add new features through build.rs.
rust-version: [ 1.34, 1.44, 1.56, 1.63, stable ]
# nightly-2022-06-17 is the last toolchain before `try_reserve_2` was stabilized.
rust-version: [ 1.34, 1.44, 1.56, nightly-2022-06-17, 1.63, stable ]
fail-fast: false
env:
RUSTFLAGS: -D warnings
Expand Down
15 changes: 13 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ fn main() {
if compiler.minor >= 56 {
println!("cargo:rustc-cfg=shrink_to");
}
if compiler.minor >= 63 {
if compiler.minor >= 63
&& (!compiler.beta || compiler.minor >= 64)
&& (!compiler.nightly || compiler.minor >= 65)
{
println!("cargo:rustc-cfg=try_reserve_2");
}
}

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

fn rustc_version() -> Option<Compiler> {
Expand All @@ -42,5 +47,11 @@ fn rustc_version() -> Option<Compiler> {
return None;
}
let minor = pieces.next()?.parse().ok()?;
Some(Compiler { minor })
let beta = version.contains("beta");
let nightly = version.contains("nightly");
Some(Compiler {
minor,
beta,
nightly,
})
}

0 comments on commit ed3afac

Please sign in to comment.