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

Allow null-pointer-optimized enums in FFI if their underlying representation is FFI safe #60300

Merged
merged 1 commit into from
May 23, 2019

Commits on May 22, 2019

  1. Allow null-pointer-optimized enums in FFI if their underlying represe…

    …ntation is FFI safe
    
    This allows types like Option<NonZeroU8> to be used in FFI without triggering the improper_ctypes lint. This works by changing the is_repr_nullable_ptr function to consider an enum E to be FFI-safe if:
    
    - E has no explicit #[repr(...)].
    - It only has two variants.
    - One of those variants is empty (meaning it has no fields).
    - The other variant has only one field.
    - That field is one of the following:
      - &T
      - &mut T
      - extern "C" fn
      - core::num::NonZero*
      - core::ptr::NonNull<T>
      - #[repr(transparent)] struct wrapper around one of the types in this list.
    - The size of E and its field are both known and are both the same size (implying E is participating in the nonnull optimization).
    mjbshaw committed May 22, 2019
    Configuration menu
    Copy the full SHA
    a31dc8e View commit details
    Browse the repository at this point in the history