Skip to content

Commit

Permalink
Change transmute()s in IdxSet::{from_slice, from_slice_mut} to casts
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Aug 9, 2018
1 parent ffdac5d commit 1601879
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/librustc_data_structures/indexed_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {

// pnkfelix wants to have this be `IdxSet<T>([Word]) and then pass
// around `&mut IdxSet<T>` or `&IdxSet<T>`.
//
// WARNING: Mapping a `&IdxSetBuf<T>` to `&IdxSet<T>` (at least today)
// requires a transmute relying on representation guarantees that may
// not hold in the future.

/// Represents a set (or packed family of sets), of some element type
/// E, where each E is identified by some unique index type `T`.
Expand Down Expand Up @@ -134,11 +130,11 @@ impl<T: Idx> IdxSetBuf<T> {

impl<T: Idx> IdxSet<T> {
unsafe fn from_slice(s: &[Word]) -> &Self {
mem::transmute(s) // (see above WARNING)
&*(s as *const [Word] as *const Self)
}

unsafe fn from_slice_mut(s: &mut [Word]) -> &mut Self {
mem::transmute(s) // (see above WARNING)
&mut *(s as *mut [Word] as *mut Self)
}
}

Expand Down

0 comments on commit 1601879

Please sign in to comment.