Skip to content

Commit

Permalink
Unrolled build for rust-lang#127354
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
rust-timer authored Jul 7, 2024
2 parents 959a2eb + ccd8dcc commit 330b654
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,20 @@ impl<T> SizedTypeProperties for T {}
/// // ^^^ error[E0616]: field `private` of struct `Struct` is private
/// ```
///
/// Only [`Sized`] fields are supported, but the container may be unsized:
/// ```
/// # use core::mem;
/// #[repr(C)]
/// pub struct Struct {
/// a: u8,
/// b: [u8],
/// }
///
/// assert_eq!(mem::offset_of!(Struct, a), 0); // OK
/// // assert_eq!(mem::offset_of!(Struct, b), 1);
/// // ^^^ error[E0277]: doesn't have a size known at compile-time
/// ```
///
/// Note that type layout is, in general, [subject to change and
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html). If
/// layout stability is required, consider using an [explicit `repr` attribute].
Expand Down

0 comments on commit 330b654

Please sign in to comment.