Skip to content

Commit 95e43bc

Browse files
authored
Merge pull request #13 from geofft/null
other-reprs: Null-pointer-optimized enums are FFI safe unless repr(C)
2 parents b4ada32 + 7753a3c commit 95e43bc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/other-reprs.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ passed through the FFI boundary.
2323
C, and is explicitly contrary to the behavior of an empty type in C++, which
2424
still consumes a byte of space.
2525

26-
* DSTs, tuples, and tagged unions are not a concept in C and as such are never
27-
FFI safe.
26+
* DST pointers (fat pointers), tuples, and enums with data (that is, non-C-like
27+
enums) are not a concept in C, and as such are never FFI-safe.
28+
29+
* As an exception to the rule on enum with data, `Option<&T>` is
30+
FFI-safe if `*const T` is FFI-safe, and they have the same
31+
representation, using the null-pointer optimization: `Some<&T>` is
32+
represented as the pointer, and `None` is represented as a null
33+
pointer. (This rule applies to any enum defined the same way as
34+
libcore's `Option` type, and using the default repr.)
2835

2936
* Tuple structs are like structs with regards to `repr(C)`, as the only
3037
difference from a struct is that the fields aren’t named.

0 commit comments

Comments
 (0)