[−][src]Static rustc_ap_rustc_lint_defs::builtin::POINTER_STRUCTURAL_MATCH
pub static POINTER_STRUCTURAL_MATCH: &Lint
The pointer_structural_match
lint detects pointers used in patterns whose behaviour
cannot be relied upon across compiler versions and optimization levels.
Example
ⓘThis example deliberately fails to compile
#![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 wide 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.