pub static ILLEGAL_FLOATING_POINT_LITERAL_PATTERN: &'static Lint
Expand description

The illegal_floating_point_literal_pattern lint detects floating-point literals used in patterns.

Example

let x = 42.0;

match x {
    5.0 => {}
    _ => {}
}

{{produces}}

Explanation

Previous versions of the compiler accepted floating-point literals in patterns, but it was later determined this was a mistake. The semantics of comparing floating-point values may not be clear in a pattern when contrasted with “structural equality”. Typically you can work around this by using a match guard, such as:


match x {
    y if y == 5.0 => {}
    _ => {}
}

This is a future-incompatible lint to transition this to a hard error in the future. See issue #41620 for more details.