Skip to content

Commit 0ada942

Browse files
committed
feature guard rather than option
1 parent 8021a42 commit 0ada942

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/codegen/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ impl MethodCodegen for Method {
21112111
#[derive(Copy, Clone)]
21122112
enum EnumVariation {
21132113
Rust,
2114-
Bitfield { use_associated_consts: bool },
2114+
Bitfield,
21152115
Consts,
21162116
ModuleConsts
21172117
}
@@ -2153,7 +2153,6 @@ enum EnumBuilder<'a> {
21532153
Bitfield {
21542154
codegen_depth: usize,
21552155
canonical_name: &'a str,
2156-
use_associated_consts: bool,
21572156
tokens: quote::Tokens,
21582157
},
21592158
Consts {
@@ -2190,11 +2189,10 @@ impl<'a> EnumBuilder<'a> {
21902189
let ident = quote::Ident::new(name);
21912190

21922191
match enum_variation {
2193-
EnumVariation::Bitfield { use_associated_consts, .. } => {
2192+
EnumVariation::Bitfield => {
21942193
EnumBuilder::Bitfield {
21952194
codegen_depth: enum_codegen_depth,
21962195
canonical_name: name,
2197-
use_associated_consts,
21982196
tokens: quote! {
21992197
#( #attrs )*
22002198
pub struct #ident (pub #repr);
@@ -2280,8 +2278,8 @@ impl<'a> EnumBuilder<'a> {
22802278
}
22812279
}
22822280

2283-
EnumBuilder::Bitfield { canonical_name, use_associated_consts, .. } => {
2284-
if use_associated_consts {
2281+
EnumBuilder::Bitfield { canonical_name, .. } => {
2282+
if ctx.options().rust_features().associated_const {
22852283
let enum_ident = ctx.rust_ident(canonical_name);
22862284
let variant_ident = ctx.rust_ident(variant_name);
22872285
result.push(quote! {
@@ -2493,9 +2491,7 @@ impl CodeGenerator for Enum {
24932491
let variation = if self.is_constified_enum_module(ctx, item) {
24942492
EnumVariation::ModuleConsts
24952493
} else if self.is_bitfield(ctx, item) {
2496-
EnumVariation::Bitfield {
2497-
use_associated_consts: ctx.options().use_associated_consts
2498-
}
2494+
EnumVariation::Bitfield
24992495
} else if self.is_rustified_enum(ctx, item) {
25002496
EnumVariation::Rust
25012497
} else {

src/features.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ macro_rules! rust_target_base {
9090
=> Stable_1_0 => 1.0;
9191
/// Rust stable 1.19
9292
=> Stable_1_19 => 1.19;
93+
/// Rust stable 1.20
94+
=> Stable_1_20 => 1.20;
9395
/// Rust stable 1.21
9496
=> Stable_1_21 => 1.21;
9597
/// Rust stable 1.25
@@ -142,6 +144,8 @@ rust_feature_def!(
142144
=> builtin_clone_impls;
143145
/// repr(align) https://github.com/rust-lang/rust/pull/47006
144146
=> repr_align;
147+
/// associated constants https://github.com/rust-lang/rust/issues/29646
148+
=> associated_const;
145149
);
146150

147151
impl From<RustTarget> for RustFeatures {
@@ -152,6 +156,10 @@ impl From<RustTarget> for RustFeatures {
152156
features.untagged_union = true;
153157
}
154158

159+
if rust_target >= RustTarget::Stable_1_20 {
160+
features.associated_const = true;
161+
}
162+
155163
if rust_target >= RustTarget::Stable_1_21 {
156164
features.builtin_clone_impls = true;
157165
}

src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,6 @@ impl Builder {
12351235
self.options.no_hash_types.insert(arg.into());
12361236
self
12371237
}
1238-
1239-
/// Use associated constants for bitfields.
1240-
pub fn use_associated_consts(mut self, doIt: bool) -> Builder {
1241-
self.options.use_associated_consts = doIt;
1242-
self
1243-
}
12441238
}
12451239

12461240
/// Configuration options for generated bindings.
@@ -1437,9 +1431,6 @@ struct BindgenOptions {
14371431

14381432
/// The set of types that we should not derive `Hash` for.
14391433
no_hash_types: RegexSet,
1440-
1441-
/// Whether to generated associated constants for bitfields.
1442-
use_associated_consts: bool,
14431434
}
14441435

14451436
/// TODO(emilio): This is sort of a lie (see the error message that results from
@@ -1534,7 +1525,6 @@ impl Default for BindgenOptions {
15341525
no_partialeq_types: Default::default(),
15351526
no_copy_types: Default::default(),
15361527
no_hash_types: Default::default(),
1537-
use_associated_consts: false,
15381528
}
15391529
}
15401530
}

0 commit comments

Comments
 (0)