mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #39683 - solson:fix-unaligned-load-librustc_metadata, r=bluss
Fix unaligned load in librustc_metadata::index. The derived `Clone` impl contains UB and will be unsafe when we fix https://github.com/rust-lang/rust/issues/27060. See [this comment](https://github.com/rust-lang/rust/issues/27060#issuecomment-278617096) for more context. r? @bluss
This commit is contained in:
commit
55c17a5994
@ -96,9 +96,17 @@ impl<'tcx> LazySeq<Index> {
|
||||
}
|
||||
|
||||
#[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 }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user