@@ -1754,55 +1754,6 @@ declare_lint! {
1754
1754
} ;
1755
1755
}
1756
1756
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
-
1806
1757
declare_lint ! {
1807
1758
/// The `unstable_name_collisions` lint detects that you have used a name
1808
1759
/// that the standard library plans to add in the future.
@@ -3334,6 +3285,31 @@ declare_lint! {
3334
3285
"name introduced by a private item shadows a name introduced by a public glob re-export" ,
3335
3286
}
3336
3287
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.
3337
3313
declare_lint_pass ! {
3338
3314
/// Does nothing as a lint pass, but registers some `Lint`s
3339
3315
/// that are used by other parts of the compiler.
@@ -3371,7 +3347,6 @@ declare_lint_pass! {
3371
3347
FUZZY_PROVENANCE_CASTS ,
3372
3348
HIDDEN_GLOB_REEXPORTS ,
3373
3349
ILL_FORMED_ATTRIBUTE_INPUT ,
3374
- ILLEGAL_FLOATING_POINT_LITERAL_PATTERN ,
3375
3350
IMPLIED_BOUNDS_ENTAILMENT ,
3376
3351
INCOMPLETE_INCLUDE ,
3377
3352
INDIRECT_STRUCTURAL_MATCH ,
@@ -3380,6 +3355,7 @@ declare_lint_pass! {
3380
3355
INVALID_ALIGNMENT ,
3381
3356
INVALID_DOC_ATTRIBUTES ,
3382
3357
INVALID_MACRO_EXPORT_ARGUMENTS ,
3358
+ INVALID_NAN_COMPARISONS ,
3383
3359
INVALID_TYPE_PARAM_DEFAULT ,
3384
3360
IRREFUTABLE_LET_PATTERNS ,
3385
3361
LARGE_ASSIGNMENTS ,
0 commit comments