pub static POINTER_STRUCTURAL_MATCH: &'static Lint
Expand description

The pointer_structural_match lint detects pointers used in patterns whose behaviour cannot be relied upon across compiler versions and optimization levels.

§Example

#![deny(pointer_structural_match)]
fn foo(a: usize, b: usize) -> usize { a + b }
const FOO: fn(usize, usize) -> usize = foo;
fn main() {
    match FOO {
        FOO => {},
        _ => {},
    }
}

{{produces}}

§Explanation

Previous versions of Rust allowed function pointers and all raw pointers in patterns. While these work in many cases as expected by users, it is possible that due to optimizations pointers are “not equal to themselves” or pointers to different functions compare as equal during runtime. This is because LLVM optimizations can deduplicate functions if their bodies are the same, thus also making pointers to these functions point to the same location. Additionally functions may get duplicated if they are instantiated in different crates and not deduplicated again via LTO. Pointer identity for memory created by const is similarly unreliable.