diff --git a/src/lib.rs b/src/lib.rs index e6b3cb8..3c342ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1353,7 +1353,8 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> { self.test_type(&i.ident.to_string()); } - ast::ItemKind::Struct(ref s, ref generics) if public => { + ast::ItemKind::Struct(ref s, ref generics) | + ast::ItemKind::Union(ref s, ref generics) if public => { self.assert_no_generics(i.ident, generics); let is_c = i.attrs.iter().any(|a| { attr::find_repr_attrs(self.sh, a).iter().any(|a| { diff --git a/testcrate/src/t1.h b/testcrate/src/t1.h index 01905c4..65423a2 100644 --- a/testcrate/src/t1.h +++ b/testcrate/src/t1.h @@ -19,6 +19,11 @@ struct T1Baz { struct T1Bar b; }; +typedef union { + uint64_t a; + uint32_t b; +} T1Union; + void T1a(void); void* T1b(void); void* T1c(void*); diff --git a/testcrate/src/t1.rs b/testcrate/src/t1.rs index 0143c80..ad0dd81 100644 --- a/testcrate/src/t1.rs +++ b/testcrate/src/t1.rs @@ -27,6 +27,12 @@ pub struct T1Baz { pub b: T1Bar, } +#[repr(C)] +pub union T1Union { + pub a: u64, + pub b: u32, +} + i! { pub const T1C: u32 = 4; } diff --git a/testcrate/src/t2.h b/testcrate/src/t2.h index 0ef984f..8746117 100644 --- a/testcrate/src/t2.h +++ b/testcrate/src/t2.h @@ -9,6 +9,11 @@ struct T2Baz { uint32_t b; }; +typedef struct { + uint32_t a; + int64_t b; +} T2Union; + static void T2a(void) {} #define T2C 4 diff --git a/testcrate/src/t2.rs b/testcrate/src/t2.rs index 35ecee5..029b46e 100644 --- a/testcrate/src/t2.rs +++ b/testcrate/src/t2.rs @@ -11,6 +11,12 @@ pub struct T2Baz { pub b: u32, } +#[repr(C)] +pub union T2Union { + pub a: u32, + pub b: i64, +} + pub const T2C: i32 = 5; i! { diff --git a/testcrate/tests/all.rs b/testcrate/tests/all.rs index a605366..e03b762 100644 --- a/testcrate/tests/all.rs +++ b/testcrate/tests/all.rs @@ -36,6 +36,9 @@ fn t2() { "bad T2a function pointer", "bad T2C value at byte 0", "bad T2S string", + "bad T2Union size", + "bad field type b of T2Union", + "bad field offset b of T2Union", ]; let mut errors = errors.iter().cloned().collect::>();