-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Types equal to/wrapping () result in "not FFI-safe" warning #66202
Comments
@Rantanen This is related to #65134 in so far as that PR made the improper-ctypes lint apply to extern functions that are outside @rkruppe @eddyb do you know if this is a bug or is expected? |
My knee-jerk reaction is that both are bugs that can and should be fixed.
|
Good to know! I was worried this was a change in functionality that wasn't expected. I've since worked around this issue by normalizing the |
How can I find this lint to be useless in my own code,it warns for things whose layout won't change. |
Passing ZSTs by value is on thin ice since zero-sized types don't exist in standard C and ABIs aren't always consistent about how they handle types that use GNU extensions to be zero-sized. The lint also fires on The special case of returning just I guess this also ties into the "linting likely mistakes in FFI code" versus "linting use of types with unspecified layout" tension that has come up in #66220 at the same time. |
That won't be a problem for me so long as Rust itself stays consistent in how it passes zero-sized types through |
That isn't really the case, though. For example, #64259 changes how ZSTs are passed in the C ABI on (some target triples of) PowerPC. That is arguably a bugfix, but it's happening because ZSTs in C are such a non-standard mess. |
I thought we fixed the normalization problem for this years ago, ugh. |
@eddyb FWIW the title change is not fully accurate, only one of the two warnings in the OP involve associated types, the other is about transparent newtypes. Arguably these are two separate issues but at present both are discussed here so both should be covered by the title. |
I had to check this but apparently we always treat returning a ZST like rust/src/librustc/ty/layout.rs Lines 2711 to 2719 in 76ade3e
(even if on some architectures passing in a ZST to C code can have strange requirements) I wonder if this logic is wrong, compared to returning If it's not, we should allow any ZSTs, or at least transparent ones (note that the code snippet above doesn't look at anything other than the size being |
This commit adds a test of the improper ctypes lint, checking that return type are normalized bethat return types are normalized before being checked for FFI-safety, and that transparent newtype wrappers are FFI-safe if the type being wrapped is FFI-safe. Signed-off-by: David Wood <[email protected]>
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=62da3bf343e1358e16a6692a72ca7f33
All of these cases work in Beta. At least the associated type warning is recent regression in Nightly. I suspect #65134
CC @davidtwco
The text was updated successfully, but these errors were encountered: