Skip to content

Rust types in FFI lint #12608

Closed
Closed
@alexcrichton

Description

@alexcrichton

Right now we have a lint mode which warns about the usage of rust types in extern blocks. This makes sure that by default you don't pass rust types into C functions. What we don't have is a lint going the other way which makes sure that C can't get Rust types from Rust. I believe that we need to expand the FFI lint to crawl extern functions as well as extern blocks.

The exact types which should be allowed is a little questionable. Some things that would be nice to have a defined ABI/FFI for would, but may currently not be working:

  • Option<&T> and Option<~T>. See Nullable-pointer Options aren't FFI-compatible with the base pointer types. #11303, but this is currently broken. Do we want to commit to this ABI and say that it's valid to use to interface with C?
  • ~T and &T, are these valid FFI types? The rust type system guarantees they are never null, but there's no guarantee that C handed you something that's not null.
  • &str - should this be valid to pass in/out? This would require something along the lines of rust.h

To be conservative, we could only allow primitives (minus int and uint) plus *T, but this is quite limiting and makes FFI a little more difficult.

Nominating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions