Skip to content

Commit cf71726

Browse files
author
bors-servo
authored
Auto merge of #600 - emilio:fwd-enum, r=upsuper
ir: Prefer the enum definition instead of the declaration when looking for variants. Fixes #599
2 parents b4e3be9 + 217cf28 commit cf71726

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/ir/enum_ty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ impl Enum {
5454
ctx: &mut BindgenContext)
5555
-> Result<Self, ParseError> {
5656
use clang_sys::*;
57+
debug!("Enum::from_ty {:?}", ty);
58+
5759
if ty.kind() != CXType_Enum {
5860
return Err(ParseError::Continue);
5961
}
@@ -82,7 +84,8 @@ impl Enum {
8284
};
8385
let type_name = type_name.as_ref().map(String::as_str);
8486

85-
declaration.visit(|cursor| {
87+
let definition = declaration.definition().unwrap_or(declaration);
88+
definition.visit(|cursor| {
8689
if cursor.kind() == CXCursor_EnumConstantDecl {
8790
let value = if is_signed {
8891
cursor.enum_val_signed().map(EnumVariantValue::Signed)
@@ -99,7 +102,7 @@ impl Enum {
99102
Annotations::new(&cursor)
100103
.and_then(|anno| if anno.hide() {
101104
Some(EnumVariantCustomBehavior::Hide)
102-
} else if
105+
} else if
103106
anno.constify_enum_variant() {
104107
Some(EnumVariantCustomBehavior::Constify)
105108
} else {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(i32)]
8+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
9+
pub enum CSSPseudoClassType { empty = 0, link = 1, }

tests/headers/forward-enum-decl.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// bindgen-flags: -- -std=c++11
2+
3+
enum class CSSPseudoClassType : int;
4+
5+
enum class CSSPseudoClassType : int {
6+
empty,
7+
link,
8+
};

0 commit comments

Comments
 (0)