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 9f7100d

Browse files
authoredJul 7, 2024
Rollup merge of rust-lang#127354 - nicholasbishop:bishop-sized-doc, r=Nilstrieb
Describe Sized requirements for mem::offset_of The container doesn't have to be sized, but the field must be sized (at least until rust-lang#126151 is stable).
2 parents ee06e7d + 1862054 commit 9f7100d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎core/src/mem/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,20 @@ impl<T> SizedTypeProperties for T {}
12661266
/// // ^^^ error[E0616]: field `private` of struct `Struct` is private
12671267
/// ```
12681268
///
1269+
/// Only [`Sized`] fields are supported, but the container may be unsized:
1270+
/// ```
1271+
/// # use core::mem;
1272+
/// #[repr(C)]
1273+
/// pub struct Struct {
1274+
/// a: u8,
1275+
/// b: [u8],
1276+
/// }
1277+
///
1278+
/// assert_eq!(mem::offset_of!(Struct, a), 0); // OK
1279+
/// // assert_eq!(mem::offset_of!(Struct, b), 1);
1280+
/// // ^^^ error[E0277]: doesn't have a size known at compile-time
1281+
/// ```
1282+
///
12691283
/// Note that type layout is, in general, [subject to change and
12701284
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html). If
12711285
/// layout stability is required, consider using an [explicit `repr` attribute].

0 commit comments

Comments
 (0)
Failed to load comments.