Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1862054

Browse files
Describe Sized requirements for mem::offset_of
The container doesn't have to be sized, but the field must be sized (atleast untilrust-lang#126151 is stable).
1 parentde4f5c2 commit1862054

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎core/src/mem/mod.rs‎

Lines changed: 14 additions & 0 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp