Skip to content

Make vtables non-zero-size to fix a rustc warning. #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,15 @@ impl<'a> CodeGenerator for Vtable<'a> {
assert_eq!(item.id(), self.item_id);
// For now, generate an empty struct, later we should generate function
// pointers and whatnot.
let mut attributes = vec![attributes::repr("C")];

if ctx.options().derive_default {
attributes.push(attributes::derives(&["Default"]))
}
let attributes = vec![attributes::repr("C")];

let vtable = aster::AstBuilder::new()
.item()
.pub_()
.with_attrs(attributes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, you're totally right, you only need to remove the if a few lines above this one that pushes the Default attr :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.struct_(self.canonical_name(ctx))
.tuple_struct(self.canonical_name(ctx))
.field()
.build_ty(helpers::ast_ty::raw_type(ctx, "c_void"))
.build();
result.push(vtable);
}
Expand Down
4 changes: 1 addition & 3 deletions tests/expectations/tests/enum_and_vtable_mangling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, }
#[repr(C)]
#[derive(Default)]
pub struct C__bindgen_vtable {
}
pub struct C__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct C {
Expand Down
4 changes: 1 addition & 3 deletions tests/expectations/tests/nested_vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@


#[repr(C)]
#[derive(Default)]
pub struct nsISupports__bindgen_vtable {
}
pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsISupports {
Expand Down
4 changes: 1 addition & 3 deletions tests/expectations/tests/ref_argument_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

pub const NSID_LENGTH: ::std::os::raw::c_uint = 10;
#[repr(C)]
#[derive(Default)]
pub struct nsID__bindgen_vtable {
}
pub struct nsID__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsID {
Expand Down
4 changes: 1 addition & 3 deletions tests/expectations/tests/virtual_dtor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@


#[repr(C)]
#[derive(Default)]
pub struct nsSlots__bindgen_vtable {
}
pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug)]
pub struct nsSlots {
Expand Down
8 changes: 2 additions & 6 deletions tests/expectations/tests/virtual_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ impl Clone for A {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Default)]
pub struct B__bindgen_vtable {
}
pub struct B__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct B {
Expand All @@ -53,9 +51,7 @@ impl Default for B {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Default)]
pub struct C__bindgen_vtable {
}
pub struct C__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct C {
Expand Down
4 changes: 1 addition & 3 deletions tests/expectations/tests/virtual_overloaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@


#[repr(C)]
#[derive(Default)]
pub struct C__bindgen_vtable {
}
pub struct C__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct C {
Expand Down
4 changes: 1 addition & 3 deletions tests/expectations/tests/vtable_recursive_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ impl Default for Derived {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Default)]
pub struct Base__bindgen_vtable {
}
pub struct Base__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Base {
Expand Down