about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-07-29 16:16:45 +1000
committerGitHub <noreply@github.com>2025-07-29 16:16:45 +1000
commite08a30856145632de973aea101d67bd288d9eaa8 (patch)
tree386ba4e884a43194a73036d86c5c447d0b4c4631
parentf9c114ef90cd22028d0c5d1976ecae8b9afa92b4 (diff)
parent72927f6eb74550e24f0fdeecd5f21201fd970d12 (diff)
downloadrust-e08a30856145632de973aea101d67bd288d9eaa8.tar.gz
rust-e08a30856145632de973aea101d67bd288d9eaa8.zip
Rollup merge of #144578 - FractalFir:m68k_fix, r=compiler-errors
Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.

The compiler relies on `hir::Lifetime` being aligned to at least 4 bytes(for the purposes of pointer tagging).

However, on some systems(like m68k) with lower alignment requirements(eg. usize / u32 aligned to 2 bytes),`hir::Lifetime` will be aligned to only 2 bytes.

This causes the compilation to fail on those systems - a const assert in the compiler fails.

This PR makes the aligement requriement of hir::Lifetime explict. This has no effect on platforms where that already is the case(repr align can only raise alignment), but ensures the alignment will stay correct no matter what.
-rw-r--r--compiler/rustc_hir/src/hir.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 96501844264..4ccc2e5a97c 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -148,6 +148,11 @@ impl From<Ident> for LifetimeSyntax {
 /// `LifetimeSource::OutlivesBound` or `LifetimeSource::PreciseCapturing`
 /// — there's no way to "elide" these lifetimes.
 #[derive(Debug, Copy, Clone, HashStable_Generic)]
+// Raise the aligement to at least 4 bytes - this is relied on in other parts of the compiler(for pointer tagging):
+// https://github.com/rust-lang/rust/blob/ce5fdd7d42aba9a2925692e11af2bd39cf37798a/compiler/rustc_data_structures/src/tagged_ptr.rs#L163
+// Removing this `repr(4)` will cause the compiler to not build on platforms like `m68k` Linux, where the aligement of u32 and usize is only 2.
+// Since `repr(align)` may only raise aligement, this has no effect on platforms where the aligement is already sufficient.
+#[repr(align(4))]
 pub struct Lifetime {
     #[stable_hasher(ignore)]
     pub hir_id: HirId,