From 68eb664b6a4b81842d07857690a37839ec4cf07a Mon Sep 17 00:00:00 2001 From: "David A. Ramos" Date: Mon, 12 Mar 2018 21:12:23 -0700 Subject: [PATCH 1/2] Clarify non-nullable pointer optimization in repr(C) section --- src/other-reprs.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index a2ce433..c9fce17 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -26,12 +26,11 @@ still consumes a byte of space. * DST pointers (fat pointers), tuples, and enums with fields are not a concept in C, and as such are never FFI-safe. -* As an exception to the rule on enum with data, `Option<&T>` is - FFI-safe if `*const T` is FFI-safe, and they have the same - representation, using the null-pointer optimization: `Some<&T>` is - represented as the pointer, and `None` is represented as a null - pointer. (This rule applies to any enum defined the same way as - libcore's `Option` type, and using the default repr.) +* If `T` is an [FFI-safe non-nullable pointer + type](ffi.html#the-nullable-pointer-optimization), + `Option` is guaranteed to have the same layout and ABI as `T` and is + therefore also FFI-safe. As of this writing, this covers `&`, `&mut`, + `Box`, and function pointers, all of which can never be null. * Tuple structs are like structs with regards to `repr(C)`, as the only difference from a struct is that the fields aren’t named. From fa41e367bf612b49805361b5590dcfec4e239014 Mon Sep 17 00:00:00 2001 From: "David A. Ramos" Date: Wed, 14 Mar 2018 19:56:35 -0700 Subject: [PATCH 2/2] Remove box --- src/other-reprs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index c9fce17..139ee4c 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -30,7 +30,7 @@ still consumes a byte of space. type](ffi.html#the-nullable-pointer-optimization), `Option` is guaranteed to have the same layout and ABI as `T` and is therefore also FFI-safe. As of this writing, this covers `&`, `&mut`, - `Box`, and function pointers, all of which can never be null. + and function pointers, all of which can never be null. * Tuple structs are like structs with regards to `repr(C)`, as the only difference from a struct is that the fields aren’t named.