Skip to content

Commit 6ac1232

Browse files
committed
Favor .cast() over as
rust-lang/rust-clippy#8017
1 parent b553b4f commit 6ac1232

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

crossbeam-channel/src/flavors/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<T> Channel<T> {
216216
return Err(msg);
217217
}
218218

219-
let slot: &Slot<T> = &*(token.array.slot as *const Slot<T>);
219+
let slot: &Slot<T> = &*token.array.slot.cast::<Slot<T>>();
220220

221221
// Write the message into the slot and update the stamp.
222222
slot.msg.get().write(MaybeUninit::new(msg));
@@ -307,7 +307,7 @@ impl<T> Channel<T> {
307307
return Err(());
308308
}
309309

310-
let slot: &Slot<T> = &*(token.array.slot as *const Slot<T>);
310+
let slot: &Slot<T> = &*token.array.slot.cast::<Slot<T>>();
311311

312312
// Read the message from the slot and update the stamp.
313313
let msg = slot.msg.get().read().assume_init();

crossbeam-channel/src/flavors/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<T> Channel<T> {
285285
}
286286

287287
// Write the message into the slot.
288-
let block = token.list.block as *mut Block<T>;
288+
let block = token.list.block.cast::<Block<T>>();
289289
let offset = token.list.offset;
290290
let slot = (*block).slots.get_unchecked(offset);
291291
slot.msg.get().write(MaybeUninit::new(msg));

crossbeam-channel/src/flavors/zero.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<T> Channel<T> {
190190
// heap-allocated packet.
191191
packet.wait_ready();
192192
let msg = packet.msg.get().replace(None).unwrap();
193-
drop(Box::from_raw(token.zero.0 as *mut Packet<T>));
193+
drop(Box::from_raw(token.zero.0.cast::<Packet<T>>()));
194194
Ok(msg)
195195
}
196196
}
@@ -409,15 +409,15 @@ impl<T> SelectHandle for Receiver<'_, T> {
409409
let mut inner = self.0.inner.lock().unwrap();
410410
inner
411411
.receivers
412-
.register_with_packet(oper, packet as *mut (), cx);
412+
.register_with_packet(oper, packet.cast::<()>(), cx);
413413
inner.senders.notify();
414414
inner.senders.can_select() || inner.is_disconnected
415415
}
416416

417417
fn unregister(&self, oper: Operation) {
418418
if let Some(operation) = self.0.inner.lock().unwrap().receivers.unregister(oper) {
419419
unsafe {
420-
drop(Box::from_raw(operation.packet as *mut Packet<T>));
420+
drop(Box::from_raw(operation.packet.cast::<Packet<T>>()));
421421
}
422422
}
423423
}
@@ -459,15 +459,15 @@ impl<T> SelectHandle for Sender<'_, T> {
459459
let mut inner = self.0.inner.lock().unwrap();
460460
inner
461461
.senders
462-
.register_with_packet(oper, packet as *mut (), cx);
462+
.register_with_packet(oper, packet.cast::<()>(), cx);
463463
inner.receivers.notify();
464464
inner.receivers.can_select() || inner.is_disconnected
465465
}
466466

467467
fn unregister(&self, oper: Operation) {
468468
if let Some(operation) = self.0.inner.lock().unwrap().senders.unregister(oper) {
469469
unsafe {
470-
drop(Box::from_raw(operation.packet as *mut Packet<T>));
470+
drop(Box::from_raw(operation.packet.cast::<Packet<T>>()));
471471
}
472472
}
473473
}

crossbeam-deque/src/deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<T> Buffer<T> {
6464
/// that would be more expensive and difficult to implement generically for all types `T`.
6565
/// Hence, as a hack, we use a volatile write instead.
6666
unsafe fn write(&self, index: isize, task: MaybeUninit<T>) {
67-
ptr::write_volatile(self.at(index) as *mut MaybeUninit<T>, task)
67+
ptr::write_volatile(self.at(index).cast::<MaybeUninit<T>>(), task)
6868
}
6969

7070
/// Reads a task from the specified `index`.
@@ -74,7 +74,7 @@ impl<T> Buffer<T> {
7474
/// that would be more expensive and difficult to implement generically for all types `T`.
7575
/// Hence, as a hack, we use a volatile load instead.
7676
unsafe fn read(&self, index: isize) -> MaybeUninit<T> {
77-
ptr::read_volatile(self.at(index) as *mut MaybeUninit<T>)
77+
ptr::read_volatile(self.at(index).cast::<MaybeUninit<T>>())
7878
}
7979
}
8080

crossbeam-epoch/src/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<T> Pointable for [MaybeUninit<T>] {
252252
let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * len;
253253
let align = mem::align_of::<Array<T>>();
254254
let layout = alloc::Layout::from_size_align(size, align).unwrap();
255-
let ptr = alloc::alloc(layout) as *mut Array<T>;
255+
let ptr = alloc::alloc(layout).cast::<Array<T>>();
256256
if ptr.is_null() {
257257
alloc::handle_alloc_error(layout);
258258
}

crossbeam-epoch/src/deferred.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ impl Deferred {
4646
unsafe {
4747
if size <= mem::size_of::<Data>() && align <= mem::align_of::<Data>() {
4848
let mut data = MaybeUninit::<Data>::uninit();
49-
ptr::write(data.as_mut_ptr() as *mut F, f);
49+
ptr::write(data.as_mut_ptr().cast::<F>(), f);
5050

5151
unsafe fn call<F: FnOnce()>(raw: *mut u8) {
52-
let f: F = ptr::read(raw as *mut F);
52+
let f: F = ptr::read(raw.cast::<F>());
5353
f();
5454
}
5555

@@ -61,12 +61,12 @@ impl Deferred {
6161
} else {
6262
let b: Box<F> = Box::new(f);
6363
let mut data = MaybeUninit::<Data>::uninit();
64-
ptr::write(data.as_mut_ptr() as *mut Box<F>, b);
64+
ptr::write(data.as_mut_ptr().cast::<Box<F>>(), b);
6565

6666
unsafe fn call<F: FnOnce()>(raw: *mut u8) {
6767
// It's safe to cast `raw` from `*mut u8` to `*mut Box<F>`, because `raw` is
6868
// originally derived from `*mut Box<F>`.
69-
let b: Box<F> = ptr::read(raw as *mut Box<F>);
69+
let b: Box<F> = ptr::read(raw.cast::<Box<F>>());
7070
(*b)();
7171
}
7272

@@ -83,7 +83,7 @@ impl Deferred {
8383
#[inline]
8484
pub(crate) fn call(mut self) {
8585
let call = self.call;
86-
unsafe { call(self.data.as_mut_ptr() as *mut u8) };
86+
unsafe { call(self.data.as_mut_ptr().cast::<u8>()) };
8787
}
8888
}
8989

crossbeam-skiplist/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<K, V> Node<K, V> {
9999
/// why this function is unsafe.
100100
unsafe fn alloc(height: usize, ref_count: usize) -> *mut Self {
101101
let layout = Self::get_layout(height);
102-
let ptr = alloc(layout) as *mut Self;
102+
let ptr = alloc(layout).cast::<Self>();
103103
if ptr.is_null() {
104104
handle_alloc_error(layout);
105105
}
@@ -118,7 +118,7 @@ impl<K, V> Node<K, V> {
118118
unsafe fn dealloc(ptr: *mut Self) {
119119
let height = (*ptr).height();
120120
let layout = Self::get_layout(height);
121-
dealloc(ptr as *mut u8, layout);
121+
dealloc(ptr.cast::<u8>(), layout);
122122
}
123123

124124
/// Returns the layout of a node with the given `height`.

crossbeam-utils/src/atomic/atomic_cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<T> AtomicCell<T> {
180180
/// ```
181181
#[inline]
182182
pub fn as_ptr(&self) -> *mut T {
183-
self.value.get() as *mut T
183+
self.value.get().cast::<T>()
184184
}
185185
}
186186

@@ -1005,7 +1005,7 @@ where
10051005
// do atomic reads and atomic writes, but we can't atomically read and write all
10061006
// kinds of data since `AtomicU8` is not available on stable Rust yet.
10071007
// Load as `MaybeUninit` because we may load a value that is not valid as `T`.
1008-
let val = ptr::read_volatile(src as *mut MaybeUninit<T>);
1008+
let val = ptr::read_volatile(src.cast::<MaybeUninit<T>>());
10091009

10101010
if lock.validate_read(stamp) {
10111011
return val.assume_init();

crossbeam-utils/src/sync/parker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Unparker {
264264
/// # let _ = unsafe { Unparker::from_raw(raw) };
265265
/// ```
266266
pub fn into_raw(this: Unparker) -> *const () {
267-
Arc::into_raw(this.inner) as *const ()
267+
Arc::into_raw(this.inner).cast::<()>()
268268
}
269269

270270
/// Converts a raw pointer into an `Unparker`.
@@ -286,7 +286,7 @@ impl Unparker {
286286
/// ```
287287
pub unsafe fn from_raw(ptr: *const ()) -> Unparker {
288288
Unparker {
289-
inner: Arc::from_raw(ptr as *const Inner),
289+
inner: Arc::from_raw(ptr.cast::<Inner>()),
290290
}
291291
}
292292
}

0 commit comments

Comments
 (0)