-
Notifications
You must be signed in to change notification settings - Fork 744
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
r=me |
This fails with: Compiling tests_expectations v0.1.0 (file:///home/simon/projects/servo-deps/rust-bindgen/tests/expectations)
error[E0277]: the trait bound `std::os::raw::c_void: std::default::Default` is not satisfied
--> tests/vtable_recursive_sig.rs:27:33
|
27 | pub struct Base__bindgen_vtable(::std::os::raw::c_void);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `std::os::raw::c_void`
|
= note: required by `std::default::Default::default` I think it’s some |
Seems like that would prevent us from deriving What about making it |
How was |
Specifically, the code generated before this PR was: #[repr(C)]
#[derive(Default)]
pub struct Base__bindgen_vtable {
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Base {
pub vtable_: *const Base__bindgen_vtable,
}
|
It's |
|
Right, but it's needed to derive |
Is it? That would require |
@@ -716,7 +716,9 @@ impl<'a> CodeGenerator for Vtable<'a> { | |||
.item() | |||
.pub_() | |||
.with_attrs(attributes) |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
``` 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 ```
@bors-servo r=fitzgen,emilio Thanks! |
📌 Commit f67967a has been approved by |
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 ``` Emilio said on IRC: > the empty vtable means that we don't care of figuring out the proper vtable layout, so we create an empty struct Sounds like all that matters is to have a pointer, we don’t look at the data behind it. Using `c_void` seems appropriate, then.
☀️ Test successful - status-travis |
Emilio said on IRC:
Sounds like all that matters is to have a pointer, we don’t look at the data behind it. Using
c_void
seems appropriate, then.