Skip to content

Commit cc010b3

Browse files
committed
Fix clippy::ptr_as_ptr warnings
1 parent b824515 commit cc010b3

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

src/deque.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ impl<T, S: VecStorage<T> + ?Sized> DequeInner<T, S> {
269269
} else if self.back <= self.front {
270270
(
271271
slice::from_raw_parts(
272-
self.buffer.borrow().as_ptr().add(self.front) as *const T,
272+
self.buffer.borrow().as_ptr().add(self.front).cast::<T>(),
273273
self.storage_capacity() - self.front,
274274
),
275-
slice::from_raw_parts(self.buffer.borrow().as_ptr() as *const T, self.back),
275+
slice::from_raw_parts(self.buffer.borrow().as_ptr().cast::<T>(), self.back),
276276
)
277277
} else {
278278
(
279279
slice::from_raw_parts(
280-
self.buffer.borrow().as_ptr().add(self.front) as *const T,
280+
self.buffer.borrow().as_ptr().add(self.front).cast::<T>(),
281281
self.back - self.front,
282282
),
283283
&[],
@@ -297,15 +297,15 @@ impl<T, S: VecStorage<T> + ?Sized> DequeInner<T, S> {
297297
} else if self.back <= self.front {
298298
(
299299
slice::from_raw_parts_mut(
300-
ptr.add(self.front) as *mut T,
300+
ptr.add(self.front).cast::<T>(),
301301
self.storage_capacity() - self.front,
302302
),
303-
slice::from_raw_parts_mut(ptr as *mut T, self.back),
303+
slice::from_raw_parts_mut(ptr.cast::<T>(), self.back),
304304
)
305305
} else {
306306
(
307307
slice::from_raw_parts_mut(
308-
ptr.add(self.front) as *mut T,
308+
ptr.add(self.front).cast::<T>(),
309309
self.back - self.front,
310310
),
311311
&mut [],

src/histbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
291291
unsafe fn drop_contents(&mut self) {
292292
unsafe {
293293
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(
294-
self.data.borrow_mut().as_mut_ptr() as *mut T,
294+
self.data.borrow_mut().as_mut_ptr().cast::<T>(),
295295
self.len(),
296296
))
297297
}
@@ -446,7 +446,7 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
446446
/// Returns the array slice backing the buffer, without keeping track
447447
/// of the write position. Therefore, the element order is unspecified.
448448
pub fn as_slice(&self) -> &[T] {
449-
unsafe { slice::from_raw_parts(self.data.borrow().as_ptr() as *const _, self.len()) }
449+
unsafe { slice::from_raw_parts(self.data.borrow().as_ptr().cast(), self.len()) }
450450
}
451451

452452
/// Returns a pair of slices which contain, in order, the contents of the buffer.

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
clippy::use_self,
145145
clippy::too_long_first_doc_paragraph,
146146
clippy::redundant_pub_crate,
147-
clippy::option_if_let_else
147+
clippy::option_if_let_else,
148+
clippy::ptr_as_ptr,
148149
)]
149150

150151
pub use binary_heap::BinaryHeap;

src/spsc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<'a, T, S: Storage> Iterator for IterMutInner<'a, T, S> {
465465
let i = (head + self.index) % self.rb.n();
466466
self.index += 1;
467467

468-
Some(unsafe { &mut *(self.rb.buffer.borrow().get_unchecked(i).get() as *mut T) })
468+
Some(unsafe { &mut *self.rb.buffer.borrow().get_unchecked(i).get().cast::<T>() })
469469
} else {
470470
None
471471
}
@@ -495,7 +495,7 @@ impl<T, S: Storage> DoubleEndedIterator for IterMutInner<'_, T, S> {
495495
// self.len > 0, since it's larger than self.index > 0
496496
let i = (head + self.len - 1) % self.rb.n();
497497
self.len -= 1;
498-
Some(unsafe { &mut *(self.rb.buffer.borrow().get_unchecked(i).get() as *mut T) })
498+
Some(unsafe { &mut *self.rb.buffer.borrow().get_unchecked(i).get().cast::<T>() })
499499
} else {
500500
None
501501
}

src/storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<const N: usize> SealedStorage for OwnedStorage<N> {
4343
N
4444
}
4545
fn as_ptr<T>(this: *mut Self::Buffer<T>) -> *mut T {
46-
this as _
46+
this.cast()
4747
}
4848
}
4949

@@ -57,6 +57,6 @@ impl SealedStorage for ViewStorage {
5757
}
5858

5959
fn as_ptr<T>(this: *mut Self::Buffer<T>) -> *mut T {
60-
this as _
60+
this.cast()
6161
}
6262
}

src/vec/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl<T, const N: usize> Vec<T, N> {
255255
pub fn into_array<const M: usize>(self) -> Result<[T; M], Self> {
256256
if self.len() == M {
257257
// This is how the unstable `MaybeUninit::array_assume_init` method does it
258-
let array = unsafe { (&self.buffer as *const _ as *const [T; M]).read() };
258+
let array = unsafe { (core::ptr::from_ref(&self.buffer).cast::<[T; M]>()).read() };
259259

260260
// We don't want `self`'s destructor to be called because that would drop all the
261261
// items in the array
@@ -431,12 +431,12 @@ impl<T> VecView<T> {
431431
impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
432432
/// Returns a raw pointer to the vector’s buffer.
433433
pub fn as_ptr(&self) -> *const T {
434-
self.buffer.borrow().as_ptr() as *const T
434+
self.buffer.borrow().as_ptr().cast::<T>()
435435
}
436436

437437
/// Returns a raw pointer to the vector’s buffer, which may be mutated through.
438438
pub fn as_mut_ptr(&mut self) -> *mut T {
439-
self.buffer.borrow_mut().as_mut_ptr() as *mut T
439+
self.buffer.borrow_mut().as_mut_ptr().cast::<T>()
440440
}
441441

442442
/// Extracts a slice containing the entire vector.
@@ -453,7 +453,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
453453
pub fn as_slice(&self) -> &[T] {
454454
// NOTE(unsafe) avoid bound checks in the slicing operation
455455
// &buffer[..self.len]
456-
unsafe { slice::from_raw_parts(self.buffer.borrow().as_ptr() as *const T, self.len) }
456+
unsafe { slice::from_raw_parts(self.buffer.borrow().as_ptr().cast::<T>(), self.len) }
457457
}
458458

459459
/// Extracts a mutable slice containing the entire vector.
@@ -473,7 +473,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
473473
// NOTE(unsafe) avoid bound checks in the slicing operation
474474
// &mut buffer[..self.len]
475475
unsafe {
476-
slice::from_raw_parts_mut(self.buffer.borrow_mut().as_mut_ptr() as *mut T, self.len)
476+
slice::from_raw_parts_mut(self.buffer.borrow_mut().as_mut_ptr().cast::<T>(), self.len)
477477
}
478478
}
479479

@@ -1317,7 +1317,7 @@ where
13171317
if self.next < self.vec.len() {
13181318
let s = unsafe {
13191319
slice::from_raw_parts(
1320-
(self.vec.buffer.buffer.as_ptr() as *const T).add(self.next),
1320+
self.vec.buffer.buffer.as_ptr().cast::<T>().add(self.next),
13211321
self.vec.len() - self.next,
13221322
)
13231323
};

0 commit comments

Comments
 (0)