The associated type used in the Bar struct causes it to trigger the warning, even though the actual type FooVtable has the #[repr(C)] attribute. Using the type directly in the Baz struct works as expected so it seems that associated types don't "inherit" the attribute correctly.
Should associated types be usable in this way?
Hopefully this is just a false warning as it does seem to work correctly, but the warning is slightly worrying.
#[repr(C)]
trait Test {
type Vtable;
}
#[repr(C)] pub struct Foo;
#[repr(C)] pub struct FooVtable;
impl Test for Foo {
type Vtable = FooVtable;
}
#[repr(C)] pub struct Bar {
base: <Foo as Test>::Vtable
}
#[repr(C)] pub struct Baz {
base: FooVtable
}
extern "C" {
pub fn external_foobar(x: *const Bar);
pub fn external_foobar_2(x: *const Baz);
}
Error:
<anon>:22:38: 22:41 warning: found type without foreign-function-safe representation annotation
in foreign module, consider adding a #[repr(...)] attribute to the type, #[warn(improper_ctypes)]
on by default
<anon>:22 pub fn external_foobar(x: *const Bar);
^~~
Playground link
Tested on stable 1.0.0 and latest nightly.
The associated type used in the
Barstruct causes it to trigger the warning, even though the actual typeFooVtablehas the#[repr(C)]attribute. Using the type directly in theBazstruct works as expected so it seems that associated types don't "inherit" the attribute correctly.Should associated types be usable in this way?
Hopefully this is just a false warning as it does seem to work correctly, but the warning is slightly worrying.
Error:
Playground link
Tested on stable 1.0.0 and latest nightly.