mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-30 16:39:26 +00:00
24 lines
445 B
Rust
24 lines
445 B
Rust
// run-rustfix
|
|
|
|
#![warn(clippy::swap_ptr_to_ref)]
|
|
|
|
use core::ptr::addr_of_mut;
|
|
|
|
fn main() {
|
|
let mut x = 0u32;
|
|
let y: *mut _ = &mut x;
|
|
let z: *mut _ = &mut x;
|
|
|
|
unsafe {
|
|
core::ptr::swap(y, z);
|
|
core::ptr::swap(y, &mut x);
|
|
core::ptr::swap(&mut x, y);
|
|
core::ptr::swap(addr_of_mut!(x), addr_of_mut!(x));
|
|
}
|
|
|
|
let y = &mut x;
|
|
let mut z = 0u32;
|
|
let z = &mut z;
|
|
|
|
core::mem::swap(y, z);
|
|
}
|