Skip to content

Bindgen ignores enum definition when declaration appears first #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
upsuper opened this issue Mar 23, 2017 · 1 comment
Closed

Bindgen ignores enum definition when declaration appears first #599

upsuper opened this issue Mar 23, 2017 · 1 comment

Comments

@upsuper
Copy link
Contributor

upsuper commented Mar 23, 2017

Input C/C++ Header

enum class CSSPseudoClassType : int;

enum class CSSPseudoClassType : int
{
  empty,
  link,
};

Bindgen Invokation

$ bindgen input.h -- -std=c++14

Actual Results

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CSSPseudoClassType { }

Expected Results

#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CSSPseudoClassType { empty = 0, link = 1, }

RUST_LOG=bindgen Output

INFO:bindgen: Clang Version: clang version 3.9.0 (tags/RELEASE_390/final)
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [] }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }, declaration: None, loc: None
DEBUG:bindgen::ir::item: Item::from_ty_with_id: ItemId(1)
	ty = Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))),
	location = Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType"))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(1), ty: Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), loc: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType"))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType")), id: ItemId(1) }]
DEBUG:bindgen::ir::item: Item::from_ty_with_id: ItemId(2)
	ty = Type(int, kind: Int, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)),
	location = Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(int, kind: Int, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(3), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("int"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: Int(Int), is_const: false, detect_has_vtable_cycle: Cell { value: false } }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("CSSPseudoClassType"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: Enum(Enum { repr: Some(ItemId(3)), variants: [] }), is_const: false, detect_has_vtable_cycle: Cell { value: false } }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }, declaration: Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), loc: Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")))
DEBUG:bindgen::ir::item: Item::from_ty_with_id: ItemId(4)
	ty = Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))),
	location = Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType"))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType"))), None
DEBUG:bindgen::ir::context: Already resolved ty ItemId(1), CanonicalTypeDeclaration(Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))), Type(CSSPseudoClassType, kind: Enum, cconv: 100, decl: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")), canon: Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:1:12, usr: Some("c:@E@CSSPseudoClassType"))) Some(Cursor(CSSPseudoClassType kind: EnumDecl, loc: test.hpp:3:12, usr: Some("c:@E@CSSPseudoClassType")))
DEBUG:bindgen::ir::context: add_builtin_item: item = Item { id: ItemId(4), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("CSSPseudoClassType"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: ResolvedTypeRef(ItemId(1)), is_const: false, detect_has_vtable_cycle: Cell { value: false } }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
DEBUG:bindgen::ir::context: No replacements to process
DEBUG:bindgen::codegen: codegen: BindgenOptions { hidden_types: RegexSet { items: [], set: Some(RegexSet([])) }, opaque_types: RegexSet { items: [], set: Some(RegexSet([])) }, whitelisted_types: RegexSet { items: [], set: Some(RegexSet([])) }, whitelisted_functions: RegexSet { items: [], set: Some(RegexSet([])) }, whitelisted_vars: RegexSet { items: [], set: Some(RegexSet([])) }, bitfield_enums: RegexSet { items: [], set: Some(RegexSet([])) }, constified_enums: RegexSet { items: [], set: Some(RegexSet([])) }, builtins: false, links: [], emit_ast: false, emit_ir: false, emit_ir_graphviz: None, enable_cxx_namespaces: false, disable_name_namespacing: false, derive_debug: true, derive_default: false, unstable_rust: true, use_core: false, ctypes_prefix: None, namespaced_constants: true, msvc_mangling: false, convert_floats: true, raw_lines: [], clang_args: ["-std=c++14", "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1", "-isystem", "/usr/local/include", "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include", "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include", "-isystem", "/usr/include", "-isystem", "/System/Library/Frameworks", "-isystem", "/Library/Frameworks", "test.hpp"], input_header: Some("test.hpp"), dummy_uses: None, parse_callbacks: None, codegen_config: CodegenConfig { functions: true, types: true, vars: true, methods: true, constructors: true }, conservative_inline_namespaces: false, generate_comments: true, generate_inline_functions: false, whitelist_recursively: true, objc_extern_crate: false, enable_mangling: true, prepend_enum_name: true }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [ItemId(1)] }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
DEBUG:bindgen::codegen: <Module as CodeGenerator>::codegen: item = Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [ItemId(1)] }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
DEBUG:bindgen::codegen: <Item as CodeGenerator>::codegen: self = Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("CSSPseudoClassType"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: Enum(Enum { repr: Some(ItemId(3)), variants: [] }), is_const: false, detect_has_vtable_cycle: Cell { value: false } }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
DEBUG:bindgen::codegen: <Type as CodeGenerator>::codegen: item = Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("CSSPseudoClassType"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: Enum(Enum { repr: Some(ItemId(3)), variants: [] }), is_const: false, detect_has_vtable_cycle: Cell { value: false } }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
DEBUG:bindgen::codegen: <Enum as CodeGenerator>::codegen: item = Item { id: ItemId(1), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Type(Type { name: Some("CSSPseudoClassType"), layout: Some(Layout { size: 4, align: 4, packed: false }), kind: Enum(Enum { repr: Some(ItemId(3)), variants: [] }), is_const: false, detect_has_vtable_cycle: Cell { value: false } }), detect_derive_debug_cycle: Cell { value: false }, detect_derive_copy_cycle: Cell { value: false } }
@emilio
Copy link
Contributor

emilio commented Mar 23, 2017

Fix over #600

bors-servo pushed a commit that referenced this issue Mar 23, 2017
ir: Prefer the enum definition instead of the declaration when looking for variants.

Fixes #599
bors-servo pushed a commit that referenced this issue Mar 27, 2017
ir: Prefer the enum definition instead of the declaration when looking for variants.

Fixes #599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants