Skip to content
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

FFI: improper_ctypes warning when using associated type in FFI signature #26230

Closed
ghost opened this issue Jun 11, 2015 · 2 comments
Closed

FFI: improper_ctypes warning when using associated type in FFI signature #26230

ghost opened this issue Jun 11, 2015 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@ghost
Copy link

ghost commented Jun 11, 2015

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.

@steveklabnik steveklabnik added the A-associated-items Area: Associated items (types, constants & functions) label Jun 15, 2015
@ghost
Copy link
Author

ghost commented Jul 16, 2015

Investigating this, seems to be caused by the following code in librustc/middle/ty.rs which classifies all associated types as (among other things) FFI unsafe. This doesn't seem correct but I don't understand it enough to try and fix it.

                ...
                TyProjection(..) |
                TyParam(_) => {
                    TC::All
                }
                ...

permalink

@ghost
Copy link
Author

ghost commented Jul 26, 2015

Fixed on latest nightly, presumably by #26583.

@ghost ghost closed this as completed Jul 26, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions)
Projects
None yet
Development

No branches or pull requests

1 participant