From 6ec2b6b8275dcfc54111ca2262244b7fcb356425 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 3 Oct 2021 20:36:47 -0700 Subject: [PATCH] Clarify niche optimization on enums with reprs A repr on an enum with fields suppresses the optimization, but a repr on a fieldless enum does not. --- src/other-reprs.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index 2b5a430..fe06faf 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -91,7 +91,7 @@ manipulate its tag and fields. See [the RFC][really-tagged] for details. These `repr`s have no effect on a struct. -Adding an explicit `repr(u*)`, `repr(i*)`, or `repr(C)` to an enum suppresses the null-pointer optimization, like: +Adding an explicit `repr(u*)`, `repr(i*)`, or `repr(C)` to an enum with fields suppresses the null-pointer optimization, like: ```rust # use std::mem::size_of; @@ -110,6 +110,8 @@ assert_eq!(8, size_of::>()); assert_eq!(16, size_of::>()); ``` +This optimization still applies to fieldless enums with an explicit `repr(u*)`, `repr(i*)`, or `repr(C)`. + ## repr(packed) `repr(packed)` forces Rust to strip any padding, and only align the type to a