]> git.lizzy.rs Git - rust.git/commitdiff
Fix unaligned load in librustc_metadata::index.
authorScott Olson <scott@solson.me>
Thu, 9 Feb 2017 11:38:52 +0000 (03:38 -0800)
committerScott Olson <scott@solson.me>
Thu, 9 Feb 2017 11:38:52 +0000 (03:38 -0800)
src/librustc_metadata/index.rs

index 5b52b268849d3d6c2c080806531c62cdf6ed5d8b..db9fc870fa86a6a19f51071f255d51fde492e3f7 100644 (file)
@@ -96,9 +96,17 @@ pub fn iter_enumerated<'a>(&self,
 }
 
 #[repr(packed)]
-#[derive(Copy, Clone)]
+#[derive(Copy)]
 struct Unaligned<T>(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<T: Copy> Clone for Unaligned<T> {
+    fn clone(&self) -> Self {
+        *self
+    }
+}
+
 impl<T> Unaligned<T> {
     fn get(self) -> T { self.0 }
 }