Skip to content

Commit 25574e5

Browse files
committed
Make core::ops::Place an unsafe trait
1 parent 8e7a609 commit 25574e5

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

src/liballoc/binary_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ where T: Clone + Ord {
12111211
#[unstable(feature = "collection_placement",
12121212
reason = "placement protocol is subject to change",
12131213
issue = "30172")]
1214-
impl<'a, T> Place<T> for BinaryHeapPlace<'a, T>
1214+
unsafe impl<'a, T> Place<T> for BinaryHeapPlace<'a, T>
12151215
where T: Clone + Ord {
12161216
fn pointer(&mut self) -> *mut T {
12171217
self.place.pointer()

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub struct IntermediateBox<T: ?Sized> {
142142
#[unstable(feature = "placement_in",
143143
reason = "placement box design is still being worked out.",
144144
issue = "27779")]
145-
impl<T> Place<T> for IntermediateBox<T> {
145+
unsafe impl<T> Place<T> for IntermediateBox<T> {
146146
fn pointer(&mut self) -> *mut T {
147147
self.ptr as *mut T
148148
}

src/liballoc/linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, T> Placer<T> for FrontPlace<'a, T> {
12861286
#[unstable(feature = "collection_placement",
12871287
reason = "placement protocol is subject to change",
12881288
issue = "30172")]
1289-
impl<'a, T> Place<T> for FrontPlace<'a, T> {
1289+
unsafe impl<'a, T> Place<T> for FrontPlace<'a, T> {
12901290
fn pointer(&mut self) -> *mut T {
12911291
unsafe { &mut (*self.node.pointer()).element }
12921292
}
@@ -1341,7 +1341,7 @@ impl<'a, T> Placer<T> for BackPlace<'a, T> {
13411341
#[unstable(feature = "collection_placement",
13421342
reason = "placement protocol is subject to change",
13431343
issue = "30172")]
1344-
impl<'a, T> Place<T> for BackPlace<'a, T> {
1344+
unsafe impl<'a, T> Place<T> for BackPlace<'a, T> {
13451345
fn pointer(&mut self) -> *mut T {
13461346
unsafe { &mut (*self.node.pointer()).element }
13471347
}

src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ impl<'a, T> Placer<T> for PlaceBack<'a, T> {
25442544
#[unstable(feature = "collection_placement",
25452545
reason = "placement protocol is subject to change",
25462546
issue = "30172")]
2547-
impl<'a, T> Place<T> for PlaceBack<'a, T> {
2547+
unsafe impl<'a, T> Place<T> for PlaceBack<'a, T> {
25482548
fn pointer(&mut self) -> *mut T {
25492549
unsafe { self.vec.as_mut_ptr().offset(self.vec.len as isize) }
25502550
}

src/liballoc/vec_deque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ impl<'a, T> Placer<T> for PlaceBack<'a, T> {
25642564
#[unstable(feature = "collection_placement",
25652565
reason = "placement protocol is subject to change",
25662566
issue = "30172")]
2567-
impl<'a, T> Place<T> for PlaceBack<'a, T> {
2567+
unsafe impl<'a, T> Place<T> for PlaceBack<'a, T> {
25682568
fn pointer(&mut self) -> *mut T {
25692569
unsafe { self.vec_deque.ptr().offset(self.vec_deque.head as isize) }
25702570
}
@@ -2610,7 +2610,7 @@ impl<'a, T> Placer<T> for PlaceFront<'a, T> {
26102610
#[unstable(feature = "collection_placement",
26112611
reason = "placement protocol is subject to change",
26122612
issue = "30172")]
2613-
impl<'a, T> Place<T> for PlaceFront<'a, T> {
2613+
unsafe impl<'a, T> Place<T> for PlaceFront<'a, T> {
26142614
fn pointer(&mut self) -> *mut T {
26152615
let tail = self.vec_deque.wrap_sub(self.vec_deque.tail, 1);
26162616
unsafe { self.vec_deque.ptr().offset(tail as isize) }

src/libcore/ops/place.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
/// implementation of Place to clean up any intermediate state
2828
/// (e.g. deallocate box storage, pop a stack, etc).
2929
#[unstable(feature = "placement_new_protocol", issue = "27779")]
30-
pub trait Place<Data: ?Sized> {
30+
pub unsafe trait Place<Data: ?Sized> {
3131
/// Returns the address where the input value will be written.
3232
/// Note that the data at this address is generally uninitialized,
3333
/// and thus one should use `ptr::write` for initializing it.
34+
///
35+
/// This function must return a valid (non-zero) pointer to
36+
/// a location at which a value of type `Data` can be written.
3437
fn pointer(&mut self) -> *mut Data;
3538
}
3639

src/libstd/collections/hash/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ impl<'a, K, V> Placer<V> for Entry<'a, K, V> {
19321932
#[unstable(feature = "collection_placement",
19331933
reason = "placement protocol is subject to change",
19341934
issue = "30172")]
1935-
impl<'a, K, V> Place<V> for EntryPlace<'a, K, V> {
1935+
unsafe impl<'a, K, V> Place<V> for EntryPlace<'a, K, V> {
19361936
fn pointer(&mut self) -> *mut V {
19371937
self.bucket.read_mut().1
19381938
}

0 commit comments

Comments
 (0)