Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upimproper_ctypes complains about types that contain PhantomData #34798
Comments
This comment has been minimized.
This comment has been minimized.
|
The problem, as far as I know, is that This is because Zero Sized Types (which |
This comment has been minimized.
This comment has been minimized.
|
it also happens (although with a slightly different message) when the type is not ZST: https://is.gd/8529c8
|
This comment has been minimized.
This comment has been minimized.
|
Unfortunately, we need to use phantom data to use bindgen with C++, because a struct like: template<typename T>
struct Foo {
int bar;
};The only way we can represent that in rust is struct Foo<T> {
bar: c_int,
_phantom: PhantomData<T>,
} |
This comment has been minimized.
This comment has been minimized.
d3zd3z
commented
Dec 4, 2016
|
I've run into this issue with something similar use std::marker::PhantomData;
fn main() {
let buffer = vec![0u8; 16];
let data = Data {
ptr: &buffer[0],
phantom: PhantomData,
};
unsafe { bogus(&data) };
}
#[repr(C)]
struct Data<'a> {
ptr: *const u8,
phantom: PhantomData<&'a [u8]>,
}
extern "C" {
fn bogus(data: *const Data);
}which generates the same kind of warning:
My real use-case has other fields in the struct, which are needed to match the C API. |
emilio
referenced this issue
Dec 15, 2016
Closed
libbindgen: error: expected type, found keyword `type` #342
This comment has been minimized.
This comment has been minimized.
|
I did a little poking around to understand how unsafe this is. In https://play.rust-lang.org/?gist=24634425b2bd8707c73f09e418900ec5 you can see that the However, it is reported in debuginfo. So while passing its address across the ffi boundary is I think covered by the existing safety rules, a debugger could be confused by the duplicate labels on the struct. |
Ms2ger commentedJul 13, 2016
This comes up in bindings generated from C code that contains unions (the
__BindgenUnionFieldtype).