mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2025-03-03 12:21:26 +00:00
feature guard rather than option
This commit is contained in:
parent
8021a421cd
commit
0ada9427e9
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user