Skip to content

Commit 84cd250

Browse files
committed
Enums in offset_of: update based on est31, scottmcm & llogiq review
1 parent 4b4a5ae commit 84cd250

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/src/mem/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,11 +1292,15 @@ impl<T> SizedTypeProperties for T {}
12921292

12931293
/// Expands to the offset in bytes of a field from the beginning of the given type.
12941294
///
1295-
/// Only structs, unions and tuples are supported.
1295+
/// Structs, enums, unions and tuples are supported.
12961296
///
12971297
/// Nested field accesses may be used, but not array indexes like in `C`'s `offsetof`.
12981298
///
1299-
/// Note that the output of this macro is not stable, except for `#[repr(C)]` types.
1299+
/// Enum variants may be traversed as if they were fields. Variants themselves do
1300+
/// not have an offset.
1301+
///
1302+
/// Note that type layout is, in general, [platform-specific, and subject to
1303+
/// change](https://doc.rust-lang.org/reference/type-layout.html).
13001304
///
13011305
/// # Examples
13021306
///
@@ -1324,6 +1328,8 @@ impl<T> SizedTypeProperties for T {}
13241328
/// struct NestedB(u8);
13251329
///
13261330
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
1331+
///
1332+
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
13271333
/// ```
13281334
#[unstable(feature = "offset_of", issue = "106655")]
13291335
#[allow_internal_unstable(builtin_syntax, hint_must_use)]

0 commit comments

Comments
 (0)