From 7ed463cb5d112991c38e2b34efeeef63c55cdea4 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 12 Feb 2026 10:12:37 +0000 Subject: [PATCH 1/3] Clarify repr(rust) no-overlap rule is about structs only --- src/type-layout.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/type-layout.md b/src/type-layout.md index 0eb90c2e21..3cb88eb56c 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -164,17 +164,13 @@ r[layout.repr.rust.intro] The `Rust` representation is the default representation for nominal types without a `repr` attribute. Using this representation explicitly through a `repr` attribute is guaranteed to be the same as omitting the attribute entirely. r[layout.repr.rust.layout] -The only data layout guarantees made by this representation are those required for soundness. They are: +The only data layout guarantees made by this representation are those required for soundness. These are: - 1. The fields are properly aligned. - 2. The fields do not overlap. - 3. The alignment of the type is at least the maximum alignment of its fields. + 1. The offset of a field is divisible by that field's alignment. + 2. The alignment of the type is at least the maximum alignment of its fields. -r[layout.repr.rust.alignment] -Formally, the first guarantee means that the offset of any field is divisible by that field's alignment. - -r[layout.repr.rust.field-storage] -The second guarantee means that the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type. +r[layout.repr.rust.layout.struct] +For structs, it is further guaranteed that the fields do not overlap. That is, the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type. Be aware that the second guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct. From 6e7a9cfc396ed338a31b4554ef646665bf084c7d Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 12 Feb 2026 11:30:42 +0100 Subject: [PATCH 2/3] Fix stale "the second" reference Co-authored-by: Ralf Jung --- src/type-layout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type-layout.md b/src/type-layout.md index 3cb88eb56c..1f7cdb07ff 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -172,7 +172,7 @@ The only data layout guarantees made by this representation are those required f r[layout.repr.rust.layout.struct] For structs, it is further guaranteed that the fields do not overlap. That is, the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type. -Be aware that the second guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct. +Be aware that this guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct. r[layout.repr.rust.unspecified] There are no other guarantees of data layout made by this representation. From a9f61c2983fad6b2839704bb7196cda492011479 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 10 Mar 2026 18:40:39 +0000 Subject: [PATCH 3/3] Link "structs" in `layout.struct` We have an existing link reference definition for "structs"; let's use that to link to the appropriate item. --- src/type-layout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type-layout.md b/src/type-layout.md index 1f7cdb07ff..16dd006e2d 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -170,7 +170,7 @@ The only data layout guarantees made by this representation are those required f 2. The alignment of the type is at least the maximum alignment of its fields. r[layout.repr.rust.layout.struct] -For structs, it is further guaranteed that the fields do not overlap. That is, the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type. +For [structs], it is further guaranteed that the fields do not overlap. That is, the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type. Be aware that this guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct.