Skip to content

Commit afa6f92

Browse files
committed
Use intrinsic pointer methods
1 parent 9f714ef commit afa6f92

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

compiler/rustc_data_structures/src/functor.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_index::vec::{Idx, IndexVec};
22
use std::mem;
3-
use std::ptr;
43

54
pub trait IdFunctor: Sized {
65
type Inner;
@@ -29,12 +28,12 @@ impl<T> IdFunctor for Box<T> {
2928
let raw = Box::into_raw(self);
3029
Ok(unsafe {
3130
// SAFETY: The raw pointer points to a valid value of type `T`.
32-
let value = ptr::read(raw);
31+
let value = raw.read();
3332
// SAFETY: Converts `Box<T>` to `Box<MaybeUninit<T>>` which is the
3433
// inverse of `Box::assume_init()` and should be safe.
3534
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
3635
// SAFETY: Write the mapped value back into the `Box`.
37-
ptr::write(raw.as_mut_ptr(), f(value)?);
36+
raw.write(f(value)?);
3837
// SAFETY: We just initialized `raw`.
3938
raw.assume_init()
4039
})
@@ -57,14 +56,13 @@ impl<T> IdFunctor for Vec<T> {
5756
let start = self.as_mut_ptr();
5857
for i in 0..len {
5958
let p = start.add(i);
60-
match f(ptr::read(p)) {
61-
Ok(value) => ptr::write(p, value),
59+
match f(p.read()) {
60+
Ok(val) => p.write(val),
6261
Err(err) => {
6362
// drop all other elements in self
6463
// (current element was "moved" into the call to f)
6564
for j in (0..i).chain(i + 1..len) {
66-
let p = start.add(j);
67-
ptr::drop_in_place(p);
65+
start.add(j).drop_in_place();
6866
}
6967

7068
// returning will drop self, releasing the allocation

0 commit comments

Comments
 (0)