feature guard rather than option

This commit is contained in:
M Farkas-Dyck 2018-04-01 17:46:42 -08:00
parent 8021a421cd
commit 0ada9427e9
3 changed files with 13 additions and 19 deletions

View File

@ -2111,7 +2111,7 @@ impl MethodCodegen for Method {
#[derive(Copy, Clone)]
enum EnumVariation {
Rust,
Bitfield { use_associated_consts: bool },
Bitfield,
Consts,
ModuleConsts
}
@ -2153,7 +2153,6 @@ enum EnumBuilder<'a> {
Bitfield {
codegen_depth: usize,
canonical_name: &'a str,
use_associated_consts: bool,
tokens: quote::Tokens,
},
Consts {
@ -2190,11 +2189,10 @@ impl<'a> EnumBuilder<'a> {
let ident = quote::Ident::new(name);
match enum_variation {
EnumVariation::Bitfield { use_associated_consts, .. } => {
EnumVariation::Bitfield => {
EnumBuilder::Bitfield {
codegen_depth: enum_codegen_depth,
canonical_name: name,
use_associated_consts,
tokens: quote! {
#( #attrs )*
pub struct #ident (pub #repr);
@ -2280,8 +2278,8 @@ impl<'a> EnumBuilder<'a> {
}
}
EnumBuilder::Bitfield { canonical_name, use_associated_consts, .. } => {
if use_associated_consts {
EnumBuilder::Bitfield { canonical_name, .. } => {
if ctx.options().rust_features().associated_const {
let enum_ident = ctx.rust_ident(canonical_name);
let variant_ident = ctx.rust_ident(variant_name);
result.push(quote! {
@ -2493,9 +2491,7 @@ impl CodeGenerator for Enum {
let variation = if self.is_constified_enum_module(ctx, item) {
EnumVariation::ModuleConsts
} else if self.is_bitfield(ctx, item) {
EnumVariation::Bitfield {
use_associated_consts: ctx.options().use_associated_consts
}
EnumVariation::Bitfield
} else if self.is_rustified_enum(ctx, item) {
EnumVariation::Rust
} else {

View File

@ -90,6 +90,8 @@ macro_rules! rust_target_base {
=> Stable_1_0 => 1.0;
/// Rust stable 1.19
=> Stable_1_19 => 1.19;
/// Rust stable 1.20
=> Stable_1_20 => 1.20;
/// Rust stable 1.21
=> Stable_1_21 => 1.21;
/// Rust stable 1.25
@ -142,6 +144,8 @@ rust_feature_def!(
=> builtin_clone_impls;
/// repr(align) https://github.com/rust-lang/rust/pull/47006
=> repr_align;
/// associated constants https://github.com/rust-lang/rust/issues/29646
=> associated_const;
);
impl From<RustTarget> for RustFeatures {
@ -152,6 +156,10 @@ impl From<RustTarget> for RustFeatures {
features.untagged_union = true;
}
if rust_target >= RustTarget::Stable_1_20 {
features.associated_const = true;
}
if rust_target >= RustTarget::Stable_1_21 {
features.builtin_clone_impls = true;
}

View File

@ -1235,12 +1235,6 @@ impl Builder {
self.options.no_hash_types.insert(arg.into());
self
}
/// Use associated constants for bitfields.
pub fn use_associated_consts(mut self, doIt: bool) -> Builder {
self.options.use_associated_consts = doIt;
self
}
}
/// Configuration options for generated bindings.
@ -1437,9 +1431,6 @@ struct BindgenOptions {
/// The set of types that we should not derive `Hash` for.
no_hash_types: RegexSet,
/// Whether to generated associated constants for bitfields.
use_associated_consts: bool,
}
/// TODO(emilio): This is sort of a lie (see the error message that results from
@ -1534,7 +1525,6 @@ impl Default for BindgenOptions {
no_partialeq_types: Default::default(),
no_copy_types: Default::default(),
no_hash_types: Default::default(),
use_associated_consts: false,
}
}
}