diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-04-02 07:07:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 07:07:30 -0400 |
commit | fb7e51968d471099e8fee5aa876898b1469a392a (patch) | |
tree | 378b1ff6476e8a3cffb81dd048a689460bb40ebb | |
parent | fb069e9391ebf40ec9ebef7c0ac2e50f5ead5644 (diff) | |
parent | d31ed35908301c1e89883c8e5a3e8b2183ae688f (diff) |
Auto merge of #1290 - emilio:what-a-language, r=pepyakin
ir: Remove an assertion that happens to be invalid.
You can define a struct declared in an outer scope inside another struct.
C, what a language.
Fixes #1281
-rw-r--r-- | src/ir/comp.rs | 3 | ||||
-rw-r--r-- | tests/expectations/tests/issue-1281.rs | 74 | ||||
-rw-r--r-- | tests/headers/issue-1281.h | 11 |
3 files changed, 87 insertions, 1 deletions
diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 131851fd..8c2be498 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1290,9 +1290,10 @@ impl CompInfo { return CXChildVisit_Continue; } + // Even if this is a definition, we may not be the semantic + // parent, see #1281. let inner = Item::parse(cur, Some(potential_id), ctx) .expect("Inner ClassDecl"); - assert_eq!(ctx.resolve_item(inner).parent_id(), potential_id); let inner = inner.expect_type_id(ctx); diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs new file mode 100644 index 00000000..cfc8ca40 --- /dev/null +++ b/tests/expectations/tests/issue-1281.rs @@ -0,0 +1,74 @@ +/* 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 bar { + pub u: foo, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct foo { + pub foo: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::<foo>(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::<foo>(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<foo>())).foo as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) + ); +} +#[test] +fn bindgen_test_layout_bar() { + assert_eq!( + ::std::mem::size_of::<bar>(), + 4usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::<bar>(), + 4usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<bar>())).u as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) + ); +} +pub type bar_t = bar; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct baz { + pub f: foo, +} +#[test] +fn bindgen_test_layout_baz() { + assert_eq!( + ::std::mem::size_of::<baz>(), + 4usize, + concat!("Size of: ", stringify!(baz)) + ); + assert_eq!( + ::std::mem::align_of::<baz>(), + 4usize, + concat!("Alignment of ", stringify!(baz)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<baz>())).f as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) + ); +} diff --git a/tests/headers/issue-1281.h b/tests/headers/issue-1281.h new file mode 100644 index 00000000..4a3aaab0 --- /dev/null +++ b/tests/headers/issue-1281.h @@ -0,0 +1,11 @@ +struct foo; + +typedef struct bar { + struct foo { + int foo; + } u; +} bar_t; + +struct baz { + struct foo f; +}; |