require rustc 1.28.0

This commit is contained in:
Trevor Spiteri 2018-08-13 12:10:53 +02:00
parent c2504d67ab
commit f043eacbfa
3 changed files with 31 additions and 5 deletions

View File

@ -107,6 +107,8 @@ You also need to declare it by adding this to your crate root (usually
extern crate fixed; extern crate fixed;
``` ```
The *fixed* crate requires rustc version 1.28.0 or later.
## License ## License
This crate is free software: you can redistribute it and/or modify it This crate is free software: you can redistribute it and/or modify it

View File

@ -24,22 +24,39 @@ fn main() {
}; };
env.check_feature( env.check_feature(
"repr_transparent", "repr_transparent",
Optional(false),
TRY_REPR_TRANSPARENT, TRY_REPR_TRANSPARENT,
Some("repr_transparent"), Some("repr_transparent"),
); );
} }
#[derive(PartialEq)]
struct Optional(bool);
impl Environment { impl Environment {
fn check_feature(&self, name: &str, contents: &str, nightly_features: Option<&str>) { // 1. If optional feature is availble (both with and without flag), output:
// cargo:rustc-cfg=<name>
// 2. If feature is available with flag (both optional and not), output:
// cargo:rustc-cfg_nightly=<name>
// 3. If non-optional feature is not available, panic.
fn check_feature(
&self,
name: &str,
optional: Optional,
contents: &str,
nightly_features: Option<&str>,
) {
let try_dir = self.out_dir.join(format!("try_{}", name)); let try_dir = self.out_dir.join(format!("try_{}", name));
let filename = format!("try_{}.rs", name); let filename = format!("try_{}.rs", name);
create_dir_or_panic(&try_dir); create_dir_or_panic(&try_dir);
println!("$ cd {:?}", try_dir); println!("$ cd {:?}", try_dir);
#[derive(PartialEq)]
enum Iteration { enum Iteration {
Stable, Stable,
Unstable, Unstable,
} }
let mut found = false;
for i in &[Iteration::Stable, Iteration::Unstable] { for i in &[Iteration::Stable, Iteration::Unstable] {
let s; let s;
let file_contents = match *i { let file_contents = match *i {
@ -61,15 +78,20 @@ impl Environment {
.status() .status()
.unwrap_or_else(|_| panic!("Unable to execute: {:?}", cmd)); .unwrap_or_else(|_| panic!("Unable to execute: {:?}", cmd));
if status.success() { if status.success() {
println!("cargo:rustc-cfg={}", name); if !optional.0 {
if let Iteration::Unstable = *i { println!("cargo:rustc-cfg={}", name);
}
if *i == Iteration::Unstable {
println!("cargo:rustc-cfg=nightly_{}", name); println!("cargo:rustc-cfg=nightly_{}", name);
} }
found = true;
break; break;
} }
} }
remove_dir_or_panic(&try_dir); remove_dir_or_panic(&try_dir);
if !found && !optional.0 {
panic!("essential feature not supported by compiler: {}", name);
}
} }
} }

View File

@ -75,6 +75,8 @@ You also need to declare it by adding this to your crate root (usually
extern crate fixed; extern crate fixed;
``` ```
The *fixed* crate requires rustc version 1.28.0 or later.
## License ## License
This crate is free software: you can redistribute it and/or modify it This crate is free software: you can redistribute it and/or modify it
@ -306,7 +308,7 @@ macro_rules! fixed {
"[const generics]: https://github.com/rust-lang/rust/issues/44580\n", "[const generics]: https://github.com/rust-lang/rust/issues/44580\n",
"[typenum crate]: https://crates.io/crates/typenum\n" "[typenum crate]: https://crates.io/crates/typenum\n"
), ),
#[cfg_attr(repr_transparent, repr(transparent))] #[repr(transparent)]
pub struct $Fixed<Frac: Unsigned>(($Inner, PhantomData<Frac>)); pub struct $Fixed<Frac: Unsigned>(($Inner, PhantomData<Frac>));
} }