Rust

Rust

Made by DeepSource

Found manual implementation of std::ptr::eq on references RS-W1119

Anti-pattern
Minor

std::ptr::eq can be used to compare &T references (coerced to *const T implicitly) by their address rather than the values they point to. Hence, use std::ptr::eq when applicable with &T references.

Bad practice

fn main() {
    let a = &[1, 2, 3];
    let b = &[1, 2, 3];

    assert!(a as *const _ as usize == b as *const _ as usize);
}

Recommended

fn main() {
    let a = &[1, 2, 3];
    let b = &[1, 2, 3];

    assert!(std::ptr::eq(a, b));
}