summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/ty.rs8
-rw-r--r--tests/expectations/tests/anon_enum.rs5
-rw-r--r--tests/expectations/tests/issue-410.rs3
-rw-r--r--tests/expectations/tests/struct_typedef.rs61
-rw-r--r--tests/headers/struct_typedef.h15
5 files changed, 86 insertions, 6 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 78ae6cb2..91fbc6e9 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -1074,6 +1074,14 @@ impl Type {
}
CXType_Enum => {
let enum_ = Enum::from_ty(ty, ctx).expect("Not an enum?");
+
+ if name.is_empty() {
+ let pretty_name = ty.spelling();
+ if Self::is_valid_identifier(&pretty_name) {
+ name = pretty_name;
+ }
+ }
+
TypeKind::Enum(enum_)
}
CXType_Record => {
diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs
index 07ea4810..71abc77b 100644
--- a/tests/expectations/tests/anon_enum.rs
+++ b/tests/expectations/tests/anon_enum.rs
@@ -34,9 +34,6 @@ fn bindgen_test_layout_Test() {
impl Clone for Test {
fn clone(&self) -> Self { *self }
}
-pub const Foo: _bindgen_ty_1 = _bindgen_ty_1::Foo;
-pub const Bar: _bindgen_ty_1 = _bindgen_ty_1::Bar;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum _bindgen_ty_1 { Foo = 0, Bar = 1, }
-pub use self::_bindgen_ty_1 as Baz;
+pub enum Baz { Foo = 0, Bar = 1, }
diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs
index 2fe0f99b..3c6cd280 100644
--- a/tests/expectations/tests/issue-410.rs
+++ b/tests/expectations/tests/issue-410.rs
@@ -38,6 +38,5 @@ pub mod root {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
- pub enum _bindgen_ty_1 { }
- pub use self::super::root::_bindgen_ty_1 as JSWhyMagic;
+ pub enum JSWhyMagic { }
}
diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs
new file mode 100644
index 00000000..63811bda
--- /dev/null
+++ b/tests/expectations/tests/struct_typedef.rs
@@ -0,0 +1,61 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct typedef_named_struct {
+ pub has_name: bool,
+}
+#[test]
+fn bindgen_test_layout_typedef_named_struct() {
+ assert_eq!(::std::mem::size_of::<typedef_named_struct>() , 1usize , concat
+ ! ( "Size of: " , stringify ! ( typedef_named_struct ) ));
+ assert_eq! (::std::mem::align_of::<typedef_named_struct>() , 1usize ,
+ concat ! (
+ "Alignment of " , stringify ! ( typedef_named_struct ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const typedef_named_struct ) ) . has_name as *
+ const _ as usize } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( typedef_named_struct )
+ , "::" , stringify ! ( has_name ) ));
+}
+impl Clone for typedef_named_struct {
+ fn clone(&self) -> Self { *self }
+}
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct _bindgen_ty_1 {
+ pub no_name: *mut ::std::os::raw::c_void,
+}
+#[test]
+fn bindgen_test_layout__bindgen_ty_1() {
+ assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 8usize , concat ! (
+ "Size of: " , stringify ! ( _bindgen_ty_1 ) ));
+ assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 8usize , concat ! (
+ "Alignment of " , stringify ! ( _bindgen_ty_1 ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const _bindgen_ty_1 ) ) . no_name as * const _
+ as usize } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
+ , stringify ! ( no_name ) ));
+}
+impl Clone for _bindgen_ty_1 {
+ fn clone(&self) -> Self { *self }
+}
+impl Default for _bindgen_ty_1 {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
+pub type struct_ptr_t = *mut _bindgen_ty_1;
+pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1;
+#[repr(u32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum typedef_named_enum { ENUM_HAS_NAME = 1, }
+pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON;
+#[repr(u32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum _bindgen_ty_2 { ENUM_IS_ANON = 0, }
+pub type enum_ptr_t = *mut _bindgen_ty_2;
+pub type enum_ptr_ptr_t = *mut *mut _bindgen_ty_2;
diff --git a/tests/headers/struct_typedef.h b/tests/headers/struct_typedef.h
new file mode 100644
index 00000000..fdce9a72
--- /dev/null
+++ b/tests/headers/struct_typedef.h
@@ -0,0 +1,15 @@
+typedef struct {
+ _Bool has_name;
+} typedef_named_struct;
+
+typedef struct {
+ void *no_name;
+} *struct_ptr_t, **struct_ptr_ptr_t;
+
+typedef enum {
+ ENUM_HAS_NAME=1
+} typedef_named_enum;
+
+typedef enum {
+ ENUM_IS_ANON
+} *enum_ptr_t, **enum_ptr_ptr_t;