summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/mod.rs22
-rw-r--r--tests/expectations/tests/issue-946.rs21
-rw-r--r--tests/headers/issue-946.h5
3 files changed, 40 insertions, 8 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index af202a02..0ad4e805 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -614,14 +614,20 @@ impl CodeGenerator for Type {
.resolve(ctx);
let name = item.canonical_name(ctx);
- // Try to catch the common pattern:
- //
- // typedef struct foo { ... } foo;
- //
- // here.
- //
- if inner_item.canonical_name(ctx) == name {
- return;
+ {
+ let through_type_aliases = inner.into_resolver()
+ .through_type_refs()
+ .through_type_aliases()
+ .resolve(ctx);
+
+ // Try to catch the common pattern:
+ //
+ // typedef struct foo { ... } foo;
+ //
+ // here, and also other more complex cases like #946.
+ if through_type_aliases.canonical_name(ctx) == name {
+ return;
+ }
}
// If this is a known named type, disallow generating anything
diff --git a/tests/expectations/tests/issue-946.rs b/tests/expectations/tests/issue-946.rs
new file mode 100644
index 00000000..14ed38c6
--- /dev/null
+++ b/tests/expectations/tests/issue-946.rs
@@ -0,0 +1,21 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct foo {}
+#[test]
+fn bindgen_test_layout_foo() {
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 0usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+}
+pub type bar = foo;
diff --git a/tests/headers/issue-946.h b/tests/headers/issue-946.h
new file mode 100644
index 00000000..5d145e09
--- /dev/null
+++ b/tests/headers/issue-946.h
@@ -0,0 +1,5 @@
+struct foo { };
+
+typedef struct foo bar;
+
+typedef bar foo;