From 1fa86069f0c5f74481a03d9679364bd76337df06 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 11 Mar 2026 12:40:08 -0400 Subject: [PATCH 1/6] Guarantee alignment of fixed-width integer primitives --- 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 16dd006e2d..fcafb6e81c 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -46,7 +46,7 @@ r[layout.primitive.size-int] `usize` and `isize` have a size big enough to contain every address on the target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64 bit target, this is 8 bytes. r[layout.primitive.align] -The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. +The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. Alignment is guaranteed to be the same for signed and unsigned variants – that is, for a given `N`, `align_of::() == align_of::()`. r[layout.pointer] ## Pointers and references layout From 86463e6e6b4b83ebab89bf88e7796188c1a6f0d3 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 11 Mar 2026 12:42:20 -0400 Subject: [PATCH 2/6] [layout] Fix style --- 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 fcafb6e81c..7d5c9a2cd3 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -46,7 +46,7 @@ r[layout.primitive.size-int] `usize` and `isize` have a size big enough to contain every address on the target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64 bit target, this is 8 bytes. r[layout.primitive.align] -The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. Alignment is guaranteed to be the same for signed and unsigned variants – that is, for a given `N`, `align_of::() == align_of::()`. +The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. Alignment is guaranteed to be the same for signed and unsigned variants -- that is, for a given `N`, `align_of::() == align_of::()`. r[layout.pointer] ## Pointers and references layout From 7d4b9ff9fca6a70d00432a771fe357de34a604e9 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Wed, 11 Mar 2026 22:30:48 +0000 Subject: [PATCH 3/6] Separate integer alignment guarantee into new rule The purpose of the existing `layout.primitive.align` rule is to state that the alignment of primitives is platform-specific. Adding a separate alignment guarantee for integers overloads this a bit. Let's instead separate out the rules; we'll rename the existing rule since there are now two rules speaking to alignment. --- src/type-layout.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/type-layout.md b/src/type-layout.md index 7d5c9a2cd3..050204657e 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -45,8 +45,11 @@ The size of most primitives is given in this table. r[layout.primitive.size-int] `usize` and `isize` have a size big enough to contain every address on the target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64 bit target, this is 8 bytes. -r[layout.primitive.align] -The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. Alignment is guaranteed to be the same for signed and unsigned variants -- that is, for a given `N`, `align_of::() == align_of::()`. +r[layout.primitive.platform-specific-alignment] +The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. + +r[layout.primitive.integer-alignment] +Alignment is guaranteed to be the same for signed and unsigned variants -- that is, for a given `N`, `align_of::() == align_of::()`. r[layout.pointer] ## Pointers and references layout From 43165ac2c6eaf01c085f0533ff00d26ee1a914fb Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Wed, 11 Mar 2026 22:23:16 +0000 Subject: [PATCH 4/6] Revise wording of integer alignment guarantee Let's make this wording a bit more clear, and let's fix the em dash to use `---` since that's what our renderer expects. --- 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 050204657e..fdf5d76421 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -49,7 +49,7 @@ r[layout.primitive.platform-specific-alignment] The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. r[layout.primitive.integer-alignment] -Alignment is guaranteed to be the same for signed and unsigned variants -- that is, for a given `N`, `align_of::() == align_of::()`. +Alignment is guaranteed to be the same for fixed-width signed and unsigned integer variants of the same indicated size --- that is, for a given size `N`, `align_of::() == align_of::()`. r[layout.pointer] ## Pointers and references layout From 23dd1c77e7f706713f81526af04a23373ee508b3 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Fri, 27 Mar 2026 09:56:21 -0400 Subject: [PATCH 5/6] Guarantee more equalities --- src/type-layout.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/type-layout.md b/src/type-layout.md index 4c66c6bfa7..225fba3f26 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -45,8 +45,8 @@ The size of most primitives is given in this table. r[layout.primitive.size-minimum] `usize` and `isize` have a size big enough to contain every address on the target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64 bit target, this is 8 bytes. -r[layout.primitive.usize-isize-size-align] -`usize` and `isize` have the same size and alignment. +r[layout.primitive.usize-isize-size-alignment] +Let `N` be the number of bits in a `usize` on a given platform (specifically, `size_of::() * 8`). On that platform, `usize`, `isize`, `uN`, and `iN` all have the same size and alignment. r[layout.primitive.platform-specific-alignment] The alignment of primitives is platform-specific. In most cases, their alignment is equal to their size, but it may be less. In particular, `i128` and `u128` are often aligned to 4 or 8 bytes even though their size is 16, and on many 32-bit platforms, `i64`, `u64`, and `f64` are only aligned to 4 bytes, not 8. @@ -54,6 +54,9 @@ The alignment of primitives is platform-specific. In most cases, their alignment r[layout.primitive.integer-alignment] Alignment is guaranteed to be the same for fixed-width signed and unsigned integer variants of the same indicated size --- that is, for a given size `N`, `align_of::() == align_of::()`. +r[layout.primitive.char-size-alignment] +`char` is guaranteed to have the same size and alignment as `u32`. + r[layout.pointer] ## Pointers and references layout From bca20ebc06a582815a89b25927a245cd19d6b434 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Fri, 27 Mar 2026 09:59:13 -0400 Subject: [PATCH 6/6] Char alignment --- src/type-layout.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/type-layout.md b/src/type-layout.md index 225fba3f26..0f5ee663c9 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -54,8 +54,8 @@ The alignment of primitives is platform-specific. In most cases, their alignment r[layout.primitive.integer-alignment] Alignment is guaranteed to be the same for fixed-width signed and unsigned integer variants of the same indicated size --- that is, for a given size `N`, `align_of::() == align_of::()`. -r[layout.primitive.char-size-alignment] -`char` is guaranteed to have the same size and alignment as `u32`. +r[layout.primitive.char-alignment] +`char` is guaranteed to have the same alignment as `u32`. r[layout.pointer] ## Pointers and references layout