about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/ptr_eq.fixed
blob: f0150e6784b482659c8584a19eae0fa4521f765e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![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

    // Do not lint: the rhs conversion is needed
    let _ = a.as_ptr() == b as *const _;

    // Do not lint: we have two raw pointers already
    let _ = a.as_ptr() == b.as_ptr();

    // Do not lint
    let _ = mac!(a, b);
    let _ = another_mac!(a, b);

    let a = &mut [1, 2, 3];
    let b = &mut [1, 2, 3];

    // Do not lint: the rhs conversion is needed
    let _ = a.as_mut_ptr() == b as *mut [i32] as *mut _;

    // Do not lint: we have two raw pointers already
    let _ = a.as_mut_ptr() == b.as_mut_ptr();

    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

    #[expect(clippy::eq_op)]
    // Do not lint: casts are needed to not change type
    let _issue14337 = main as *const () == main as *const ();

    // Do not peel the content of macros
    let _ = std::ptr::eq(mac!(cast a), mac!(cast b));
    //~^ ptr_eq
}