Skip to content

Commit 7cf00d4

Browse files
authored
Clarify niche optimization on enums with reprs (#315)
1 parent e0aa678 commit 7cf00d4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/other-reprs.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ manipulate its tag and fields. See [the RFC][really-tagged] for details.
9191

9292
These `repr`s have no effect on a struct.
9393

94-
Adding an explicit `repr(u*)`, `repr(i*)`, or `repr(C)` to an enum suppresses the null-pointer optimization, like:
94+
Adding an explicit `repr(u*)`, `repr(i*)`, or `repr(C)` to an enum with fields suppresses the null-pointer optimization, like:
9595

9696
```rust
9797
# use std::mem::size_of;
@@ -110,6 +110,8 @@ assert_eq!(8, size_of::<MyOption<&u16>>());
110110
assert_eq!(16, size_of::<MyReprOption<&u16>>());
111111
```
112112

113+
This optimization still applies to fieldless enums with an explicit `repr(u*)`, `repr(i*)`, or `repr(C)`.
114+
113115
## repr(packed)
114116

115117
`repr(packed)` forces Rust to strip any padding, and only align the type to a

0 commit comments

Comments
 (0)