]> git.lizzy.rs Git - rust.git/commit
Allow null-pointer-optimized enums in FFI if their underlying representation is FFI...
authorMichael Bradshaw <mjbshaw@google.com>
Wed, 22 May 2019 13:49:43 +0000 (06:49 -0700)
committerMichael Bradshaw <mjbshaw@google.com>
Wed, 22 May 2019 14:24:28 +0000 (07:24 -0700)
commita31dc8e3b153ac3073f9fb14d8e523a350fe10f2
treeb167a1dabb4ded350807e1245a9b99dfd5019938
parent37ff5d388f8c004ca248adb635f1cc84d347eda0
Allow null-pointer-optimized enums in FFI if their underlying representation 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).
src/libcore/num/mod.rs
src/libcore/ptr.rs
src/librustc_lint/types.rs
src/libsyntax/feature_gate.rs
src/libsyntax_pos/symbol.rs
src/test/ui/feature-gates/feature-gate-rustc-attrs-1.rs
src/test/ui/feature-gates/feature-gate-rustc-attrs-1.stderr
src/test/ui/lint/lint-ctypes-enum.rs
src/test/ui/lint/lint-ctypes-enum.stderr