Skip to content

Commit 5eaa7c2

Browse files
committed
Fix unaligned load in librustc_metadata::index.
1 parent fd2f8a4 commit 5eaa7c2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/librustc_metadata/index.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,17 @@ impl<'tcx> LazySeq<Index> {
9696
}
9797

9898
#[repr(packed)]
99-
#[derive(Copy, Clone)]
99+
#[derive(Copy)]
100100
struct Unaligned<T>(T);
101101

102+
// The derived Clone impl is unsafe for this packed struct since it needs to pass a reference to
103+
// the field to `T::clone`, but this reference may not be properly aligned.
104+
impl<T: Copy> Clone for Unaligned<T> {
105+
fn clone(&self) -> Self {
106+
*self
107+
}
108+
}
109+
102110
impl<T> Unaligned<T> {
103111
fn get(self) -> T { self.0 }
104112
}

0 commit comments

Comments
 (0)