Skip to content

Commit

Permalink
Auto merge of #80 - RalfJung:raw, r=Amanieu
Browse files Browse the repository at this point in the history
cast the entire slice to a raw pointer, not just the first element

A strict reading of pointer provenance implies that when a `&T` gets cast to `*const T`, you may only use the raw pointer to access that `T`, not its neighbors.  That's what Miri currently implements, though it is less strict around statics (which is why this one does not currently cause a Miri failure -- I'd like to make Miri more strict though).

Cc rust-lang/unsafe-code-guidelines#134
  • Loading branch information
bors committed May 28, 2019
2 parents 4368aa4 + 2693d12 commit c765ea0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ impl<T> RawTable<T> {
pub fn new() -> Self {
Self {
data: NonNull::dangling(),
ctrl: NonNull::from(&Group::static_empty()[0]),
// Be careful to cast the entire slice to a raw pointer.
ctrl: unsafe { NonNull::new_unchecked(Group::static_empty().as_ptr() as *mut u8) },
bucket_mask: 0,
items: 0,
growth_left: 0,
Expand Down

0 comments on commit c765ea0

Please sign in to comment.