-
Notifications
You must be signed in to change notification settings - Fork 279
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 section suggests dangerous practice of using empty opaque type #29
Comments
How is this dangerous? |
with Actually, just passing a |
|
Glad we agree on that. :)
While these types are fine, I am worried that people will quickly move to variables or function arguments of type This happened e.g. in https://github.com/briansmith/ring/, where |
I’ve opened #44 to recommend zero-size structs with a private field, instead. rust-lang/rust#45225 (comment) is another case of Bad Things happening with empty enums used in types that are not "impossible". |
The FFI section of the Nomicon currently suggests to use an empty type for "opaque pointer types". That seems pretty dangerous. This came up in the discussion at rust-lang/rfcs#1861, and also in https://internals.rust-lang.org/t/recent-change-to-make-exhaustiveness-and-uninhabited-types-play-nicer-together/4602 many were not happy with using the empty type here.
Until we have proper opaque types, the safer suggestion seems to be do use a ZST with a private field, rather than an empty type. Then at least the type is not actively lying.
The text was updated successfully, but these errors were encountered: