Skip to content

Commit 9decacc

Browse files
committed
Make vtables non-zero-size to fix a rustc warning.
``` warning: found non-foreign-function-safe member in struct marked #[repr(C)]: found zero-size struct in foreign module, consider adding a member to this struct ```
1 parent cc6f3b2 commit 9decacc

8 files changed

+11
-17
lines changed

src/codegen/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ impl<'a> CodeGenerator for Vtable<'a> {
716716
.item()
717717
.pub_()
718718
.with_attrs(attributes)
719-
.struct_(self.canonical_name(ctx))
719+
.tuple_struct(self.canonical_name(ctx))
720+
.field()
721+
.build_ty(helpers::ast_ty::raw_type(ctx, "c_void"))
720722
.build();
721723
result.push(vtable);
722724
}

tests/expectations/tests/enum_and_vtable_mangling.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
1111
pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, }
1212
#[repr(C)]
1313
#[derive(Default)]
14-
pub struct C__bindgen_vtable {
15-
}
14+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
1615
#[repr(C)]
1716
#[derive(Debug, Copy)]
1817
pub struct C {

tests/expectations/tests/nested_vtable.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#[repr(C)]
88
#[derive(Default)]
9-
pub struct nsISupports__bindgen_vtable {
10-
}
9+
pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void);
1110
#[repr(C)]
1211
#[derive(Debug, Copy)]
1312
pub struct nsISupports {

tests/expectations/tests/ref_argument_array.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
pub const NSID_LENGTH: ::std::os::raw::c_uint = 10;
88
#[repr(C)]
99
#[derive(Default)]
10-
pub struct nsID__bindgen_vtable {
11-
}
10+
pub struct nsID__bindgen_vtable(::std::os::raw::c_void);
1211
#[repr(C)]
1312
#[derive(Debug, Copy)]
1413
pub struct nsID {

tests/expectations/tests/virtual_dtor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#[repr(C)]
88
#[derive(Default)]
9-
pub struct nsSlots__bindgen_vtable {
10-
}
9+
pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void);
1110
#[repr(C)]
1211
#[derive(Debug)]
1312
pub struct nsSlots {

tests/expectations/tests/virtual_inheritance.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ impl Clone for A {
2626
}
2727
#[repr(C)]
2828
#[derive(Default)]
29-
pub struct B__bindgen_vtable {
30-
}
29+
pub struct B__bindgen_vtable(::std::os::raw::c_void);
3130
#[repr(C)]
3231
#[derive(Debug, Copy)]
3332
pub struct B {
@@ -54,8 +53,7 @@ impl Default for B {
5453
}
5554
#[repr(C)]
5655
#[derive(Default)]
57-
pub struct C__bindgen_vtable {
58-
}
56+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
5957
#[repr(C)]
6058
#[derive(Debug, Copy)]
6159
pub struct C {

tests/expectations/tests/virtual_overloaded.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#[repr(C)]
88
#[derive(Default)]
9-
pub struct C__bindgen_vtable {
10-
}
9+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
1110
#[repr(C)]
1211
#[derive(Debug, Copy)]
1312
pub struct C {

tests/expectations/tests/vtable_recursive_sig.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ impl Default for Derived {
2424
}
2525
#[repr(C)]
2626
#[derive(Default)]
27-
pub struct Base__bindgen_vtable {
28-
}
27+
pub struct Base__bindgen_vtable(::std::os::raw::c_void);
2928
#[repr(C)]
3029
#[derive(Debug, Copy)]
3130
pub struct Base {

0 commit comments

Comments
 (0)