Skip to content

Commit c765ea0

Browse files
committed
Auto merge of #80 - RalfJung:raw, r=Amanieu
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
2 parents 4368aa4 + 2693d12 commit c765ea0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: src/raw/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ impl<T> RawTable<T> {
357357
pub fn new() -> Self {
358358
Self {
359359
data: NonNull::dangling(),
360-
ctrl: NonNull::from(&Group::static_empty()[0]),
360+
// Be careful to cast the entire slice to a raw pointer.
361+
ctrl: unsafe { NonNull::new_unchecked(Group::static_empty().as_ptr() as *mut u8) },
361362
bucket_mask: 0,
362363
items: 0,
363364
growth_left: 0,

0 commit comments

Comments
 (0)