Skip to content

Commit f67967a

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 1abd864 commit f67967a

8 files changed

+11
-17
lines changed

src/codegen/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,9 @@ impl<'a> CodeGenerator for Vtable<'a> {
712712
.item()
713713
.pub_()
714714
.with_attrs(attributes)
715-
.struct_(self.canonical_name(ctx))
715+
.tuple_struct(self.canonical_name(ctx))
716+
.field()
717+
.build_ty(helpers::ast_ty::raw_type(ctx, "c_void"))
716718
.build();
717719
result.push(vtable);
718720
}

tests/expectations/tests/enum_and_vtable_mangling.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
1010
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1111
pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, }
1212
#[repr(C)]
13-
pub struct C__bindgen_vtable {
14-
}
13+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
1514
#[repr(C)]
1615
#[derive(Debug, Copy)]
1716
pub struct C {

tests/expectations/tests/nested_vtable.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66

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

tests/expectations/tests/ref_argument_array.rs

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

77
pub const NSID_LENGTH: ::std::os::raw::c_uint = 10;
88
#[repr(C)]
9-
pub struct nsID__bindgen_vtable {
10-
}
9+
pub struct nsID__bindgen_vtable(::std::os::raw::c_void);
1110
#[repr(C)]
1211
#[derive(Debug, Copy)]
1312
pub struct nsID {

tests/expectations/tests/virtual_dtor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66

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

tests/expectations/tests/virtual_inheritance.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ impl Clone for A {
2525
fn clone(&self) -> Self { *self }
2626
}
2727
#[repr(C)]
28-
pub struct B__bindgen_vtable {
29-
}
28+
pub struct B__bindgen_vtable(::std::os::raw::c_void);
3029
#[repr(C)]
3130
#[derive(Debug, Copy)]
3231
pub struct B {
@@ -52,8 +51,7 @@ impl Default for B {
5251
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
5352
}
5453
#[repr(C)]
55-
pub struct C__bindgen_vtable {
56-
}
54+
pub struct C__bindgen_vtable(::std::os::raw::c_void);
5755
#[repr(C)]
5856
#[derive(Debug, Copy)]
5957
pub struct C {

tests/expectations/tests/virtual_overloaded.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66

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

tests/expectations/tests/vtable_recursive_sig.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ impl Default for Derived {
2323
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
2424
}
2525
#[repr(C)]
26-
pub struct Base__bindgen_vtable {
27-
}
26+
pub struct Base__bindgen_vtable(::std::os::raw::c_void);
2827
#[repr(C)]
2928
#[derive(Debug, Copy)]
3029
pub struct Base {

0 commit comments

Comments
 (0)