Skip to content

Commit d248c37

Browse files
committed
Ignore blocklisted enum variants.
1 parent a747712 commit d248c37

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

bindgen/ir/context.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ pub(crate) struct BindgenContext {
553553

554554
/// A map of all enum variants, mapping the variant name to
555555
/// the generated constant name and/or path.
556-
enum_variants: HashMap<String, syn::Expr>,
556+
enum_variants: HashMap<String, (ItemId, syn::Expr)>,
557557

558558
/// The set of (`ItemId`s of) types that can't derive debug.
559559
///
@@ -2826,15 +2826,19 @@ If you encounter an error missing from this list, please file an issue or a PR!"
28262826

28272827
use crate::EnumVariation;
28282828

2829+
let enum_canonical_name = if ty.name().is_some() {
2830+
Some(self.rust_ident(item.canonical_name(self)))
2831+
} else {
2832+
None
2833+
};
2834+
28292835
for variant in enum_ty.variants() {
28302836
let variant_name = self.rust_ident(variant.name());
28312837

2832-
let variant_expr = if ty.name().is_some() {
2833-
let enum_canonical_name =
2834-
item.canonical_name(self);
2835-
let enum_canonical_name =
2836-
self.rust_ident(enum_canonical_name);
2837-
2838+
let variant_expr = if let Some(
2839+
enum_canonical_name,
2840+
) = &enum_canonical_name
2841+
{
28382842
match variation {
28392843
EnumVariation::Rust { .. } |
28402844
EnumVariation::NewType {
@@ -2851,7 +2855,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
28512855
EnumVariation::Consts { .. } => {
28522856
let constant_name = self
28532857
.enum_variant_const_name(
2854-
Some(&enum_canonical_name),
2858+
Some(enum_canonical_name),
28552859
&variant_name,
28562860
);
28572861
syn::parse_quote! { #constant_name }
@@ -2868,7 +2872,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
28682872

28692873
self.enum_variants.insert(
28702874
variant.name().to_owned(),
2871-
variant_expr,
2875+
(item.id(), variant_expr),
28722876
);
28732877
}
28742878
}
@@ -2932,12 +2936,17 @@ If you encounter an error missing from this list, please file an issue or a PR!"
29322936
}
29332937

29342938
/// Get the generated name of an enum variant.
2935-
pub(crate) fn enum_variant(&self, variant: &str) -> Option<&syn::Expr> {
2939+
pub(crate) fn enum_variant(
2940+
&self,
2941+
variant: &str,
2942+
) -> Option<(ItemId, &syn::Expr)> {
29362943
assert!(
29372944
self.in_codegen_phase(),
29382945
"We only compute enum_variants when we enter codegen",
29392946
);
2940-
self.enum_variants.get(variant)
2947+
self.enum_variants
2948+
.get(variant)
2949+
.map(|(item_id, variant)| (*item_id, variant))
29412950
}
29422951

29432952
/// Look up whether `id` refers to an `enum` whose underlying type is
@@ -3230,7 +3239,14 @@ impl cmacro::CodegenContext for BindgenContext {
32303239
}
32313240

32323241
fn resolve_enum_variant(&self, variant: &str) -> Option<syn::Expr> {
3233-
self.enum_variant(variant).cloned()
3242+
let (item_id, enum_variant) = self.enum_variant(variant)?;
3243+
3244+
let item = self.resolve_item(item_id);
3245+
if item.is_blocklisted(self) {
3246+
return None;
3247+
}
3248+
3249+
Some(enum_variant.clone())
32343250
}
32353251

32363252
fn resolve_ty(&self, ty: &str) -> Option<syn::Type> {

0 commit comments

Comments
 (0)