Merge pull request #60 from ramosbugs/other_reprs_nullable_opt

Clarify non-nullable pointer optimization in repr(C) section
pull/61/head
Alexis Beingessner 7 years ago committed by GitHub
commit 6a8f0a27e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,12 +26,11 @@ still consumes a byte of space.
* DST pointers (fat pointers), tuples, and enums with fields are not a concept * DST pointers (fat pointers), tuples, and enums with fields are not a concept
in C, and as such are never FFI-safe. in C, and as such are never FFI-safe.
* As an exception to the rule on enum with data, `Option<&T>` is * If `T` is an [FFI-safe non-nullable pointer
FFI-safe if `*const T` is FFI-safe, and they have the same type](ffi.html#the-nullable-pointer-optimization),
representation, using the null-pointer optimization: `Some<&T>` is `Option<T>` is guaranteed to have the same layout and ABI as `T` and is
represented as the pointer, and `None` is represented as a null therefore also FFI-safe. As of this writing, this covers `&`, `&mut`,
pointer. (This rule applies to any enum defined the same way as and function pointers, all of which can never be null.
libcore's `Option` type, and using the default repr.)
* Tuple structs are like structs with regards to `repr(C)`, as the only * Tuple structs are like structs with regards to `repr(C)`, as the only
difference from a struct is that the fields arent named. difference from a struct is that the fields arent named.

Loading…
Cancel
Save