diff --git a/src/librustc_metadata/index.rs b/src/librustc_metadata/index.rs index 5b52b268849d3..db9fc870fa86a 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 } }