Skip to content

Commit 5761a88

Browse files
committed
Add tests for dependent qualified types.
1 parent cebb2d1 commit 5761a88

8 files changed

+433
-6
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
#[repr(C)]
9+
#[derive(Debug, Default, Copy, Clone)]
10+
pub struct InnerType {
11+
pub foo: ::std::os::raw::c_int,
12+
pub foo2: ::std::os::raw::c_int,
13+
}
14+
pub type InnerType_related_type = ::std::os::raw::c_int;
15+
impl __bindgen_has_inner_type_related_type for InnerType {
16+
type related_type = InnerType_related_type;
17+
}
18+
#[test]
19+
fn bindgen_test_layout_InnerType() {
20+
assert_eq!(
21+
::std::mem::size_of::<InnerType>(),
22+
8usize,
23+
concat!("Size of: ", stringify!(InnerType))
24+
);
25+
assert_eq!(
26+
::std::mem::align_of::<InnerType>(),
27+
4usize,
28+
concat!("Alignment of ", stringify!(InnerType))
29+
);
30+
assert_eq!(
31+
unsafe {
32+
&(*(::std::ptr::null::<InnerType>())).foo as *const _ as usize
33+
},
34+
0usize,
35+
concat!(
36+
"Offset of field: ",
37+
stringify!(InnerType),
38+
"::",
39+
stringify!(foo)
40+
)
41+
);
42+
assert_eq!(
43+
unsafe {
44+
&(*(::std::ptr::null::<InnerType>())).foo2 as *const _ as usize
45+
},
46+
4usize,
47+
concat!(
48+
"Offset of field: ",
49+
stringify!(InnerType),
50+
"::",
51+
stringify!(foo2)
52+
)
53+
);
54+
}
55+
#[repr(C)]
56+
#[derive(Debug, Default, Copy, Clone)]
57+
pub struct Container<ContainedType>
58+
where
59+
ContainedType: __bindgen_has_inner_type_related_type,
60+
{
61+
pub contents_: Container_content_ty<ContainedType>,
62+
pub _phantom_0:
63+
::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
64+
}
65+
pub type Container_content_ty<ContainedType> =
66+
<ContainedType as __bindgen_has_inner_type_related_type>::related_type;
67+
pub type Concrete = Container<InnerType>;
68+
#[repr(C)]
69+
#[derive(Debug, Default, Copy, Clone)]
70+
pub struct LaterContainingType {
71+
pub outer_contents: Concrete,
72+
}
73+
#[test]
74+
fn bindgen_test_layout_LaterContainingType() {
75+
assert_eq!(
76+
::std::mem::size_of::<LaterContainingType>(),
77+
4usize,
78+
concat!("Size of: ", stringify!(LaterContainingType))
79+
);
80+
assert_eq!(
81+
::std::mem::align_of::<LaterContainingType>(),
82+
4usize,
83+
concat!("Alignment of ", stringify!(LaterContainingType))
84+
);
85+
assert_eq!(
86+
unsafe {
87+
&(*(::std::ptr::null::<LaterContainingType>())).outer_contents
88+
as *const _ as usize
89+
},
90+
0usize,
91+
concat!(
92+
"Offset of field: ",
93+
stringify!(LaterContainingType),
94+
"::",
95+
stringify!(outer_contents)
96+
)
97+
);
98+
}
99+
pub trait __bindgen_has_inner_type_related_type {
100+
type related_type: std::fmt::Debug + Default + Copy + Clone;
101+
}
102+
#[test]
103+
fn __bindgen_test_layout_Container_open0_InnerType_close0_instantiation() {
104+
assert_eq!(
105+
::std::mem::size_of::<Container<InnerType>>(),
106+
4usize,
107+
concat!(
108+
"Size of template specialization: ",
109+
stringify!(Container<InnerType>)
110+
)
111+
);
112+
assert_eq!(
113+
::std::mem::align_of::<Container<InnerType>>(),
114+
4usize,
115+
concat!(
116+
"Alignment of template specialization: ",
117+
stringify!(Container<InnerType>)
118+
)
119+
);
120+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
#[repr(C)]
9+
#[derive(Debug, Default, Copy, Clone)]
10+
pub struct InnerType {
11+
pub foo: ::std::os::raw::c_long,
12+
}
13+
pub type InnerType_related_type = ::std::os::raw::c_int;
14+
impl __bindgen_has_inner_type_related_type for InnerType {
15+
type related_type = InnerType_related_type;
16+
}
17+
#[test]
18+
fn bindgen_test_layout_InnerType() {
19+
assert_eq!(
20+
::std::mem::size_of::<InnerType>(),
21+
8usize,
22+
concat!("Size of: ", stringify!(InnerType))
23+
);
24+
assert_eq!(
25+
::std::mem::align_of::<InnerType>(),
26+
8usize,
27+
concat!("Alignment of ", stringify!(InnerType))
28+
);
29+
assert_eq!(
30+
unsafe {
31+
&(*(::std::ptr::null::<InnerType>())).foo as *const _ as usize
32+
},
33+
0usize,
34+
concat!(
35+
"Offset of field: ",
36+
stringify!(InnerType),
37+
"::",
38+
stringify!(foo)
39+
)
40+
);
41+
}
42+
#[repr(C)]
43+
#[derive(Debug, Default, Copy, Clone)]
44+
pub struct Container<ContainedType>
45+
where
46+
ContainedType: __bindgen_has_inner_type_related_type,
47+
{
48+
pub contents_:
49+
<ContainedType as __bindgen_has_inner_type_related_type>::related_type,
50+
pub _phantom_0:
51+
::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
52+
}
53+
pub type Concrete = Container<InnerType>;
54+
pub trait __bindgen_has_inner_type_related_type {
55+
type related_type: std::fmt::Debug + Default + Copy + Clone;
56+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
#[repr(C)]
9+
#[derive(Debug, Default, Copy, Clone)]
10+
pub struct InnerTypeA {
11+
pub foo: ::std::os::raw::c_int,
12+
pub foo2: ::std::os::raw::c_int,
13+
}
14+
pub type InnerTypeA_related_type = ::std::os::raw::c_int;
15+
impl __bindgen_has_inner_type_related_type for InnerTypeA {
16+
type related_type = InnerTypeA_related_type;
17+
}
18+
#[test]
19+
fn bindgen_test_layout_InnerTypeA() {
20+
assert_eq!(
21+
::std::mem::size_of::<InnerTypeA>(),
22+
8usize,
23+
concat!("Size of: ", stringify!(InnerTypeA))
24+
);
25+
assert_eq!(
26+
::std::mem::align_of::<InnerTypeA>(),
27+
4usize,
28+
concat!("Alignment of ", stringify!(InnerTypeA))
29+
);
30+
assert_eq!(
31+
unsafe {
32+
&(*(::std::ptr::null::<InnerTypeA>())).foo as *const _ as usize
33+
},
34+
0usize,
35+
concat!(
36+
"Offset of field: ",
37+
stringify!(InnerTypeA),
38+
"::",
39+
stringify!(foo)
40+
)
41+
);
42+
assert_eq!(
43+
unsafe {
44+
&(*(::std::ptr::null::<InnerTypeA>())).foo2 as *const _ as usize
45+
},
46+
4usize,
47+
concat!(
48+
"Offset of field: ",
49+
stringify!(InnerTypeA),
50+
"::",
51+
stringify!(foo2)
52+
)
53+
);
54+
}
55+
#[repr(C)]
56+
#[derive(Debug, Default, Copy, Clone)]
57+
pub struct InnerTypeB {
58+
pub bar: ::std::os::raw::c_ulong,
59+
}
60+
pub type InnerTypeB_related_type = ::std::os::raw::c_char;
61+
impl __bindgen_has_inner_type_related_type for InnerTypeB {
62+
type related_type = InnerTypeB_related_type;
63+
}
64+
#[test]
65+
fn bindgen_test_layout_InnerTypeB() {
66+
assert_eq!(
67+
::std::mem::size_of::<InnerTypeB>(),
68+
8usize,
69+
concat!("Size of: ", stringify!(InnerTypeB))
70+
);
71+
assert_eq!(
72+
::std::mem::align_of::<InnerTypeB>(),
73+
8usize,
74+
concat!("Alignment of ", stringify!(InnerTypeB))
75+
);
76+
assert_eq!(
77+
unsafe {
78+
&(*(::std::ptr::null::<InnerTypeB>())).bar as *const _ as usize
79+
},
80+
0usize,
81+
concat!(
82+
"Offset of field: ",
83+
stringify!(InnerTypeB),
84+
"::",
85+
stringify!(bar)
86+
)
87+
);
88+
}
89+
#[repr(C)]
90+
#[derive(Debug, Default, Copy, Clone)]
91+
pub struct Container<ContainedType>
92+
where
93+
ContainedType: __bindgen_has_inner_type_related_type,
94+
{
95+
pub contents_: Container_content_ty<ContainedType>,
96+
pub _phantom_0:
97+
::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
98+
}
99+
pub type Container_content_ty<ContainedType> =
100+
<ContainedType as __bindgen_has_inner_type_related_type>::related_type;
101+
pub type Concrete = Container<InnerTypeA>;
102+
#[repr(C)]
103+
#[derive(Debug, Default, Copy, Clone)]
104+
pub struct LaterContainingType {
105+
pub outer_contents_a: Concrete,
106+
pub outer_contents_b: Container<InnerTypeB>,
107+
}
108+
#[test]
109+
fn bindgen_test_layout_LaterContainingType() {
110+
assert_eq!(
111+
::std::mem::size_of::<LaterContainingType>(),
112+
8usize,
113+
concat!("Size of: ", stringify!(LaterContainingType))
114+
);
115+
assert_eq!(
116+
::std::mem::align_of::<LaterContainingType>(),
117+
4usize,
118+
concat!("Alignment of ", stringify!(LaterContainingType))
119+
);
120+
assert_eq!(
121+
unsafe {
122+
&(*(::std::ptr::null::<LaterContainingType>())).outer_contents_a
123+
as *const _ as usize
124+
},
125+
0usize,
126+
concat!(
127+
"Offset of field: ",
128+
stringify!(LaterContainingType),
129+
"::",
130+
stringify!(outer_contents_a)
131+
)
132+
);
133+
assert_eq!(
134+
unsafe {
135+
&(*(::std::ptr::null::<LaterContainingType>())).outer_contents_b
136+
as *const _ as usize
137+
},
138+
4usize,
139+
concat!(
140+
"Offset of field: ",
141+
stringify!(LaterContainingType),
142+
"::",
143+
stringify!(outer_contents_b)
144+
)
145+
);
146+
}
147+
pub trait __bindgen_has_inner_type_related_type {
148+
type related_type: std::fmt::Debug + Default + Copy + Clone;
149+
}
150+
#[test]
151+
fn __bindgen_test_layout_Container_open0_InnerTypeA_close0_instantiation() {
152+
assert_eq!(
153+
::std::mem::size_of::<Container<InnerTypeA>>(),
154+
4usize,
155+
concat!(
156+
"Size of template specialization: ",
157+
stringify!(Container<InnerTypeA>)
158+
)
159+
);
160+
assert_eq!(
161+
::std::mem::align_of::<Container<InnerTypeA>>(),
162+
4usize,
163+
concat!(
164+
"Alignment of template specialization: ",
165+
stringify!(Container<InnerTypeA>)
166+
)
167+
);
168+
}
169+
#[test]
170+
fn __bindgen_test_layout_Container_open0_InnerTypeB_close0_instantiation() {
171+
assert_eq!(
172+
::std::mem::size_of::<Container<InnerTypeB>>(),
173+
1usize,
174+
concat!(
175+
"Size of template specialization: ",
176+
stringify!(Container<InnerTypeB>)
177+
)
178+
);
179+
assert_eq!(
180+
::std::mem::align_of::<Container<InnerTypeB>>(),
181+
1usize,
182+
concat!(
183+
"Alignment of template specialization: ",
184+
stringify!(Container<InnerTypeB>)
185+
)
186+
);
187+
}

tests/expectations/tests/issue-544-stylo-creduce-2.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
)]
77

88
#[repr(C)]
9-
pub struct Foo {
10-
pub member: Foo_SecondAlias,
9+
#[derive(Debug, Copy, Clone)]
10+
pub struct Foo<T>
11+
where
12+
T: __bindgen_has_inner_type_Associated,
13+
{
14+
pub member: Foo_SecondAlias<i32>,
15+
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
1116
}
12-
pub type Foo_FirstAlias = [u8; 0usize];
13-
pub type Foo_SecondAlias = [u8; 0usize];
14-
impl Default for Foo {
17+
pub type Foo_FirstAlias<T> =
18+
<T as __bindgen_has_inner_type_Associated>::Associated;
19+
pub type Foo_SecondAlias<T> = Foo<Foo_FirstAlias<T>>;
20+
impl<T> Default for Foo<T> {
1521
fn default() -> Self {
1622
unsafe { ::std::mem::zeroed() }
1723
}
1824
}
25+
pub trait __bindgen_has_inner_type_Associated {
26+
type Associated: std::fmt::Debug + Default + Copy + Clone;
27+
}

0 commit comments

Comments
 (0)