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-safe lint should be more aggressive in checking ffi stability of sub-types #72939

Open
fschutt opened this issue Jun 3, 2020 · 0 comments
Labels
A-ffi Area: Foreign Function Interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@fschutt
Copy link
Contributor

fschutt commented Jun 3, 2020

According to this answer, this code:

pub struct A { a: usize, b: usize }

#[repr(C)] 
pub struct B { 
    a: A 
}

... should emit a warning that struct A is still #[repr(Rust)], so the layout of B isn't completely defined, specifically the order of the fields a and b are not specified in #[repr(Rust)]. I'm not sure if the ffi-safe lint is active or not, but it would be very useful, so I know that if a type is marked #[repr(C)], all sub-types are also marked #[repr(C)].

Another question: When compiling to a cdylib, why does cargo use #[repr(Rust)] for publicly visible structs of a crate. It would be nice if, when compiling to a cdylib with this code:

pub fn foo(b: B) -> A { b.a }

... there could be automatic warnings:

  • foo is a public function, should be marked as #[no_mangle]
  • B and A should be marked as #[repr(C)]

... because the only representation that you usually want when compiling to a cdylib is #[repr(C)] (or #[repr(C, u8)] for enums).

@jonas-schievink jonas-schievink added A-ffi Area: Foreign Function Interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ffi Area: Foreign Function Interface (FFI) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

2 participants