mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 04:55:22 +03:00
db4bd96575
We do not want to remove casts done inside macros. Also, when printing the suggestion, take it from the same context as the origin expression (the root context).
62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
#![warn(clippy::ptr_eq)]
|
|
|
|
macro_rules! mac {
|
|
($a:expr, $b:expr) => {
|
|
$a as *const _ as usize == $b as *const _ as usize
|
|
};
|
|
(cast $a:expr) => {
|
|
$a as *const [i32; 3]
|
|
};
|
|
}
|
|
|
|
macro_rules! another_mac {
|
|
($a:expr, $b:expr) => {
|
|
$a as *const _ == $b as *const _
|
|
};
|
|
}
|
|
|
|
fn main() {
|
|
let a = &[1, 2, 3];
|
|
let b = &[1, 2, 3];
|
|
|
|
let _ = std::ptr::eq(a, b);
|
|
//~^ ptr_eq
|
|
let _ = std::ptr::eq(a, b);
|
|
//~^ ptr_eq
|
|
let _ = std::ptr::eq(a.as_ptr(), b as *const _);
|
|
//~^ ptr_eq
|
|
let _ = std::ptr::eq(a.as_ptr(), b.as_ptr());
|
|
//~^ ptr_eq
|
|
|
|
// Do not lint
|
|
|
|
let _ = mac!(a, b);
|
|
let _ = another_mac!(a, b);
|
|
|
|
let a = &mut [1, 2, 3];
|
|
let b = &mut [1, 2, 3];
|
|
|
|
let _ = std::ptr::eq(a.as_mut_ptr(), b as *mut [i32] as *mut _);
|
|
//~^ ptr_eq
|
|
let _ = std::ptr::eq(a.as_mut_ptr(), b.as_mut_ptr());
|
|
//~^ ptr_eq
|
|
|
|
let _ = a == b;
|
|
let _ = core::ptr::eq(a, b);
|
|
|
|
let (x, y) = (&0u32, &mut 1u32);
|
|
let _ = std::ptr::eq(x, y);
|
|
//~^ ptr_eq
|
|
|
|
let _ = !std::ptr::eq(x, y);
|
|
//~^ ptr_eq
|
|
|
|
#[allow(clippy::eq_op)]
|
|
let _issue14337 = std::ptr::eq(main as *const (), main as *const ());
|
|
//~^ ptr_eq
|
|
|
|
// Do not peel the content of macros
|
|
let _ = std::ptr::eq(mac!(cast a), mac!(cast b));
|
|
//~^ ptr_eq
|
|
}
|