@@ -1754,55 +1754,6 @@ declare_lint! {
17541754 } ;
17551755}
17561756
1757- declare_lint ! {
1758- /// The `illegal_floating_point_literal_pattern` lint detects
1759- /// floating-point literals used in patterns.
1760- ///
1761- /// ### Example
1762- ///
1763- /// ```rust
1764- /// let x = 42.0;
1765- ///
1766- /// match x {
1767- /// 5.0 => {}
1768- /// _ => {}
1769- /// }
1770- /// ```
1771- ///
1772- /// {{produces}}
1773- ///
1774- /// ### Explanation
1775- ///
1776- /// Previous versions of the compiler accepted floating-point literals in
1777- /// patterns, but it was later determined this was a mistake. The
1778- /// semantics of comparing floating-point values may not be clear in a
1779- /// pattern when contrasted with "structural equality". Typically you can
1780- /// work around this by using a [match guard], such as:
1781- ///
1782- /// ```rust
1783- /// # let x = 42.0;
1784- ///
1785- /// match x {
1786- /// y if y == 5.0 => {}
1787- /// _ => {}
1788- /// }
1789- /// ```
1790- ///
1791- /// This is a [future-incompatible] lint to transition this to a hard
1792- /// error in the future. See [issue #41620] for more details.
1793- ///
1794- /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1795- /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1796- /// [future-incompatible]: ../index.md#future-incompatible-lints
1797- pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN ,
1798- Warn ,
1799- "floating-point literals cannot be used in patterns" ,
1800- @future_incompatible = FutureIncompatibleInfo {
1801- reason: FutureIncompatibilityReason :: FutureReleaseErrorDontReportInDeps ,
1802- reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>" ,
1803- } ;
1804- }
1805-
18061757declare_lint ! {
18071758 /// The `unstable_name_collisions` lint detects that you have used a name
18081759 /// that the standard library plans to add in the future.
@@ -3334,6 +3285,31 @@ declare_lint! {
33343285 "name introduced by a private item shadows a name introduced by a public glob re-export" ,
33353286}
33363287
3288+ declare_lint ! {
3289+ /// The `invalid_nan_comparisons` lint checks comparison with `f32::NAN` or `f64::NAN`
3290+ /// as one of the operand.
3291+ ///
3292+ /// ### Example
3293+ ///
3294+ /// ```rust
3295+ /// let a = 2.3f32;
3296+ /// if a == f32::NAN {}
3297+ /// if matches!(a, f32::NAN) {}
3298+ /// ```
3299+ ///
3300+ /// {{produces}}
3301+ ///
3302+ /// ### Explanation
3303+ ///
3304+ /// NaN does not compare meaningfully to anything – not
3305+ /// even itself – so those comparisons are always false.
3306+ pub INVALID_NAN_COMPARISONS ,
3307+ Warn ,
3308+ "detects invalid floating point NaN comparisons"
3309+ }
3310+
3311+ // When removing any lint here, remember to add a call to `register_removed` in `fn
3312+ // register_builtins` in the `rustc_lints` crate.
33373313declare_lint_pass ! {
33383314 /// Does nothing as a lint pass, but registers some `Lint`s
33393315 /// that are used by other parts of the compiler.
@@ -3371,7 +3347,6 @@ declare_lint_pass! {
33713347 FUZZY_PROVENANCE_CASTS ,
33723348 HIDDEN_GLOB_REEXPORTS ,
33733349 ILL_FORMED_ATTRIBUTE_INPUT ,
3374- ILLEGAL_FLOATING_POINT_LITERAL_PATTERN ,
33753350 IMPLIED_BOUNDS_ENTAILMENT ,
33763351 INCOMPLETE_INCLUDE ,
33773352 INDIRECT_STRUCTURAL_MATCH ,
@@ -3380,6 +3355,7 @@ declare_lint_pass! {
33803355 INVALID_ALIGNMENT ,
33813356 INVALID_DOC_ATTRIBUTES ,
33823357 INVALID_MACRO_EXPORT_ARGUMENTS ,
3358+ INVALID_NAN_COMPARISONS ,
33833359 INVALID_TYPE_PARAM_DEFAULT ,
33843360 IRREFUTABLE_LET_PATTERNS ,
33853361 LARGE_ASSIGNMENTS ,
0 commit comments