diff options
author | M Farkas-Dyck <strake888@gmail.com> | 2018-04-01 17:46:42 -0800 |
---|---|---|
committer | M Farkas-Dyck <strake888@gmail.com> | 2018-04-01 17:46:42 -0800 |
commit | 0ada9427e9e2b995da44195d8a49fcbfadb140fb (patch) | |
tree | cea2b826615a1d300c662c5ba4a68d067fa4b8dd | |
parent | 8021a421cdd84f7e7c125b9f009ed2e509c9dcd4 (diff) |
feature guard rather than option
-rw-r--r-- | src/codegen/mod.rs | 14 | ||||
-rw-r--r-- | src/features.rs | 8 | ||||
-rw-r--r-- | src/lib.rs | 10 |
3 files changed, 13 insertions, 19 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index d79adff8..9dc555ac 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -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 { diff --git a/src/features.rs b/src/features.rs index 866d7126..93ebbc34 100644 --- a/src/features.rs +++ b/src/features.rs @@ -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; } @@ -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, } } } |