Static rustc_ap_rustc_lint_defs::builtin::NONTRIVIAL_STRUCTURAL_MATCH[][src]

pub static NONTRIVIAL_STRUCTURAL_MATCH: &Lint
Expand description

The nontrivial_structural_match lint detects constants that are used in patterns, whose type is not structural-match and whose initializer body actually uses values that are not structural-match. So Option<NotStruturalMatch> is ok if the constant is just None.

Example

#![deny(nontrivial_structural_match)]

#[derive(Copy, Clone, Debug)]
struct NoDerive(u32);
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
impl Eq for NoDerive { }
fn main() {
    const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
    match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
}

{{produces}}

Explanation

Previous versions of Rust accepted constants in patterns, even if those constants’s types did not have PartialEq derived. Thus the compiler falls back to runtime execution of PartialEq, which can report that two constants are not equal even if they are bit-equivalent.