From 5eaa7c2d7df58f186015a40778ea888428d008e8 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 9 Feb 2017 03:38:52 -0800 Subject: [PATCH] Fix unaligned load in librustc_metadata::index. --- src/librustc_metadata/index.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_metadata/index.rs b/src/librustc_metadata/index.rs index 5b52b268849..db9fc870fa8 100644 --- a/src/librustc_metadata/index.rs +++ b/src/librustc_metadata/index.rs @@ -96,9 +96,17 @@ impl<'tcx> LazySeq { } #[repr(packed)] -#[derive(Copy, Clone)] +#[derive(Copy)] struct Unaligned(T); +// The derived Clone impl is unsafe for this packed struct since it needs to pass a reference to +// the field to `T::clone`, but this reference may not be properly aligned. +impl Clone for Unaligned { + fn clone(&self) -> Self { + *self + } +} + impl Unaligned { fn get(self) -> T { self.0 } }