Skip to content

Commit 4901c55

Browse files
committed
Replace set_data_ptr with pointer::set_ptr_value
1 parent 1e578c9 commit 4901c55

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

library/alloc/src/rc.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ impl<T: ?Sized> Rc<T> {
827827
let offset = unsafe { data_offset(ptr) };
828828

829829
// Reverse the offset to find the original RcBox.
830-
let fake_ptr = ptr as *mut RcBox<T>;
831-
let rc_ptr = unsafe { set_data_ptr(fake_ptr, (ptr as *mut u8).offset(-offset)) };
830+
let rc_ptr =
831+
unsafe { (ptr as *mut RcBox<T>).set_ptr_value((ptr as *mut u8).offset(-offset)) };
832832

833833
unsafe { Self::from_ptr(rc_ptr) }
834834
}
@@ -1154,7 +1154,7 @@ impl<T: ?Sized> Rc<T> {
11541154
Self::allocate_for_layout(
11551155
Layout::for_value(&*ptr),
11561156
|layout| Global.allocate(layout),
1157-
|mem| set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>,
1157+
|mem| (ptr as *mut RcBox<T>).set_ptr_value(mem),
11581158
)
11591159
}
11601160
}
@@ -1193,20 +1193,7 @@ impl<T> Rc<[T]> {
11931193
)
11941194
}
11951195
}
1196-
}
1197-
1198-
/// Sets the data pointer of a `?Sized` raw pointer.
1199-
///
1200-
/// For a slice/trait object, this sets the `data` field and leaves the rest
1201-
/// unchanged. For a sized raw pointer, this simply sets the pointer.
1202-
unsafe fn set_data_ptr<T: ?Sized, U>(mut ptr: *mut T, data: *mut U) -> *mut T {
1203-
unsafe {
1204-
ptr::write(&mut ptr as *mut _ as *mut *mut u8, data as *mut u8);
1205-
}
1206-
ptr
1207-
}
12081196

1209-
impl<T> Rc<[T]> {
12101197
/// Copy elements from slice into newly allocated Rc<\[T\]>
12111198
///
12121199
/// Unsafe because the caller must either take ownership or bind `T: Copy`

library/alloc/src/sync.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,7 @@ impl<T: ?Sized> Arc<T> {
844844
let offset = data_offset(ptr);
845845

846846
// Reverse the offset to find the original ArcInner.
847-
let fake_ptr = ptr as *mut ArcInner<T>;
848-
let arc_ptr = set_data_ptr(fake_ptr, (ptr as *mut u8).offset(-offset));
847+
let arc_ptr = (ptr as *mut ArcInner<T>).set_ptr_value((ptr as *mut u8).offset(-offset));
849848

850849
Self::from_ptr(arc_ptr)
851850
}
@@ -1129,7 +1128,7 @@ impl<T: ?Sized> Arc<T> {
11291128
Self::allocate_for_layout(
11301129
Layout::for_value(&*ptr),
11311130
|layout| Global.allocate(layout),
1132-
|mem| set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>,
1131+
|mem| (ptr as *mut ArcInner<T>).set_ptr_value(mem) as *mut ArcInner<T>,
11331132
)
11341133
}
11351134
}
@@ -1168,20 +1167,7 @@ impl<T> Arc<[T]> {
11681167
)
11691168
}
11701169
}
1171-
}
1172-
1173-
/// Sets the data pointer of a `?Sized` raw pointer.
1174-
///
1175-
/// For a slice/trait object, this sets the `data` field and leaves the rest
1176-
/// unchanged. For a sized raw pointer, this simply sets the pointer.
1177-
unsafe fn set_data_ptr<T: ?Sized, U>(mut ptr: *mut T, data: *mut U) -> *mut T {
1178-
unsafe {
1179-
ptr::write(&mut ptr as *mut _ as *mut *mut u8, data as *mut u8);
1180-
}
1181-
ptr
1182-
}
11831170

1184-
impl<T> Arc<[T]> {
11851171
/// Copy elements from slice into newly allocated Arc<\[T\]>
11861172
///
11871173
/// Unsafe because the caller must either take ownership or bind `T: Copy`.

0 commit comments

Comments
 (0)