mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2025-03-03 20:27:21 +00:00
codegen: Make the cyclic typedef name detection catch more cases.
By looking through typedefs, we also catch more complex cases like the ones that appear on Android's stdlib. Fixes #946
This commit is contained in:
parent
8725aea78f
commit
450970dcc1
@ -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
|
||||
|
21
tests/expectations/tests/issue-946.rs
Normal file
21
tests/expectations/tests/issue-946.rs
Normal file
@ -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;
|
5
tests/headers/issue-946.h
Normal file
5
tests/headers/issue-946.h
Normal file
@ -0,0 +1,5 @@
|
||||
struct foo { };
|
||||
|
||||
typedef struct foo bar;
|
||||
|
||||
typedef bar foo;
|
Loading…
x
Reference in New Issue
Block a user