Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8cb1b55

Browse files
committedMar 11, 2025
Move offset_of_enum documentation to unstable book; add offset_of_slice.
1 parent 47a68bb commit 8cb1b55

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed
 

‎core/src/mem/mod.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -1256,10 +1256,6 @@ impl<T> SizedTypeProperties for T {}
12561256
///
12571257
/// The offset is returned as a [`usize`].
12581258
///
1259-
/// If the nightly-only feature `offset_of_enum` is enabled,
1260-
/// `enum` variants may be traversed as if they were fields.
1261-
/// Variants themselves do not have an offset.
1262-
///
12631259
/// # Offsets of, and in, dynamically sized types
12641260
///
12651261
/// The field’s type must be [`Sized`], but it may be located in a [dynamically sized] container.
@@ -1338,11 +1334,16 @@ impl<T> SizedTypeProperties for T {}
13381334
///
13391335
/// [explicit `repr` attribute]: https://doc.rust-lang.org/reference/type-layout.html#representations
13401336
///
1337+
/// # Unstable features
1338+
///
1339+
/// The following unstable features expand the functionality of `offset_of!`:
1340+
///
1341+
/// * [`offset_of_enum`] — allows `enum` variants to be traversed as if they were fields.
1342+
/// * [`offset_of_slice`] — allows getting the offset of a field of type `[T]`.
1343+
///
13411344
/// # Examples
13421345
///
13431346
/// ```
1344-
/// #![feature(offset_of_enum)]
1345-
///
13461347
/// use std::mem;
13471348
/// #[repr(C)]
13481349
/// struct FieldStruct {
@@ -1364,20 +1365,11 @@ impl<T> SizedTypeProperties for T {}
13641365
/// struct NestedB(u8);
13651366
///
13661367
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
1367-
///
1368-
/// #[repr(u8)]
1369-
/// enum Enum {
1370-
/// A(u8, u16),
1371-
/// B { one: u8, two: u16 },
1372-
/// }
1373-
///
1374-
/// assert_eq!(mem::offset_of!(Enum, A.0), 1);
1375-
/// assert_eq!(mem::offset_of!(Enum, B.two), 2);
1376-
///
1377-
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
13781368
/// ```
13791369
///
13801370
/// [dynamically sized]: https://doc.rust-lang.org/reference/dynamically-sized-types.html
1371+
/// [`offset_of_enum`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-enum.html
1372+
/// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html
13811373
#[stable(feature = "offset_of", since = "1.77.0")]
13821374
#[allow_internal_unstable(builtin_syntax)]
13831375
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) {

0 commit comments

Comments
 (0)
Failed to load comments.