Skip to content

Commit 1254ee4

Browse files
committed
remove illegal_floating_point_literal_pattern lint
1 parent cda3588 commit 1254ee4

30 files changed

+143
-421
lines changed

compiler/rustc_lint/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ fn register_builtins(store: &mut LintStore) {
516516
"converted into hard error, see PR #118649 \
517517
<https://github.com/rust-lang/rust/pull/118649> for more information",
518518
);
519+
store.register_removed(
520+
"illegal_floating_point_literal_pattern",
521+
"no longer a warning, float patterns behave the same as `==`",
522+
);
519523
}
520524

521525
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint_defs/src/builtin.rs

-50
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ declare_lint_pass! {
4545
FUZZY_PROVENANCE_CASTS,
4646
HIDDEN_GLOB_REEXPORTS,
4747
ILL_FORMED_ATTRIBUTE_INPUT,
48-
ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
4948
INCOMPLETE_INCLUDE,
5049
INDIRECT_STRUCTURAL_MATCH,
5150
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
@@ -1873,55 +1872,6 @@ declare_lint! {
18731872
};
18741873
}
18751874

1876-
declare_lint! {
1877-
/// The `illegal_floating_point_literal_pattern` lint detects
1878-
/// floating-point literals used in patterns.
1879-
///
1880-
/// ### Example
1881-
///
1882-
/// ```rust
1883-
/// let x = 42.0;
1884-
///
1885-
/// match x {
1886-
/// 5.0 => {}
1887-
/// _ => {}
1888-
/// }
1889-
/// ```
1890-
///
1891-
/// {{produces}}
1892-
///
1893-
/// ### Explanation
1894-
///
1895-
/// Previous versions of the compiler accepted floating-point literals in
1896-
/// patterns, but it was later determined this was a mistake. The
1897-
/// semantics of comparing floating-point values may not be clear in a
1898-
/// pattern when contrasted with "structural equality". Typically you can
1899-
/// work around this by using a [match guard], such as:
1900-
///
1901-
/// ```rust
1902-
/// # let x = 42.0;
1903-
///
1904-
/// match x {
1905-
/// y if y == 5.0 => {}
1906-
/// _ => {}
1907-
/// }
1908-
/// ```
1909-
///
1910-
/// This is a [future-incompatible] lint to transition this to a hard
1911-
/// error in the future. See [issue #41620] for more details.
1912-
///
1913-
/// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1914-
/// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1915-
/// [future-incompatible]: ../index.md#future-incompatible-lints
1916-
pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1917-
Warn,
1918-
"floating-point literals cannot be used in patterns",
1919-
@future_incompatible = FutureIncompatibleInfo {
1920-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1921-
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
1922-
};
1923-
}
1924-
19251875
declare_lint! {
19261876
/// The `unstable_name_collisions` lint detects that you have used a name
19271877
/// that the standard library plans to add in the future.

compiler/rustc_mir_build/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ mir_build_extern_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed =
107107
.note = extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
108108
.label = use of extern static
109109
110-
mir_build_float_pattern = floating-point types cannot be used in patterns
111-
112110
mir_build_indirect_structural_match =
113111
to use a constant of type `{$non_sm_ty}` in a pattern, `{$non_sm_ty}` must be annotated with `#[derive(PartialEq)]`
114112

compiler/rustc_mir_build/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,6 @@ pub struct NaNPattern {
789789
pub span: Span,
790790
}
791791

792-
#[derive(LintDiagnostic)]
793-
#[diag(mir_build_float_pattern)]
794-
pub struct FloatPattern;
795-
796792
#[derive(LintDiagnostic)]
797793
#[diag(mir_build_pointer_pattern)]
798794
pub struct PointerPattern;

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::cell::Cell;
1717

1818
use super::PatCtxt;
1919
use crate::errors::{
20-
FloatPattern, IndirectStructuralMatch, InvalidPattern, NaNPattern, NonPartialEqMatch,
20+
IndirectStructuralMatch, InvalidPattern, NaNPattern, NonPartialEqMatch,
2121
NontrivialStructuralMatch, PointerPattern, TypeNotStructural, UnionPattern, UnsizedPattern,
2222
};
2323

@@ -488,16 +488,10 @@ impl<'tcx> ConstToPat<'tcx> {
488488
// Also see <https://github.com/rust-lang/rfcs/pull/3535>.
489489
let e = tcx.dcx().emit_err(NaNPattern { span });
490490
self.saw_const_match_error.set(Some(e));
491+
return Err(FallbackToOpaqueConst);
491492
} else {
492-
self.saw_const_match_lint.set(true);
493-
tcx.emit_node_span_lint(
494-
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
495-
id,
496-
span,
497-
FloatPattern,
498-
);
493+
PatKind::Constant { value: mir::Const::Ty(ty::Const::new_value(tcx, cv, ty)) }
499494
}
500-
return Err(FallbackToOpaqueConst);
501495
}
502496
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::RawPtr(..) => {
503497
// The raw pointers we see here have been "vetted" by valtree construction to be

src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ mod rustc_ok {
2020
pub fn rustc_lints() {
2121
let x = 42.0;
2222

23-
#[expect(illegal_floating_point_literal_pattern)]
24-
match x {
25-
5.0 => {}
26-
6.0 => {}
27-
_ => {}
28-
}
23+
#[expect(invalid_nan_comparisons)]
24+
let _b = x == f32::NAN;
2925
}
3026
}
3127

@@ -38,13 +34,9 @@ mod rustc_warn {
3834
pub fn rustc_lints() {
3935
let x = 42;
4036

41-
#[expect(illegal_floating_point_literal_pattern)]
37+
#[expect(invalid_nan_comparisons)]
4238
//~^ ERROR: this lint expectation is unfulfilled
43-
match x {
44-
5 => {}
45-
6 => {}
46-
_ => {}
47-
}
39+
let _b = x == 5;
4840
}
4941
}
5042

src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this lint expectation is unfulfilled
2-
--> $DIR/expect_tool_lint_rfc_2383.rs:35:14
2+
--> $DIR/expect_tool_lint_rfc_2383.rs:31:14
33
|
44
LL | #[expect(dead_code)]
55
| ^^^^^^^^^
@@ -8,31 +8,31 @@ LL | #[expect(dead_code)]
88
= help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]`
99

1010
error: this lint expectation is unfulfilled
11-
--> $DIR/expect_tool_lint_rfc_2383.rs:41:18
11+
--> $DIR/expect_tool_lint_rfc_2383.rs:37:18
1212
|
13-
LL | #[expect(illegal_floating_point_literal_pattern)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
LL | #[expect(invalid_nan_comparisons)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: this lint expectation is unfulfilled
17-
--> $DIR/expect_tool_lint_rfc_2383.rs:116:14
17+
--> $DIR/expect_tool_lint_rfc_2383.rs:108:14
1818
|
1919
LL | #[expect(clippy::almost_swapped)]
2020
| ^^^^^^^^^^^^^^^^^^^^^^
2121

2222
error: this lint expectation is unfulfilled
23-
--> $DIR/expect_tool_lint_rfc_2383.rs:124:14
23+
--> $DIR/expect_tool_lint_rfc_2383.rs:116:14
2424
|
2525
LL | #[expect(clippy::bytes_nth)]
2626
| ^^^^^^^^^^^^^^^^^
2727

2828
error: this lint expectation is unfulfilled
29-
--> $DIR/expect_tool_lint_rfc_2383.rs:130:14
29+
--> $DIR/expect_tool_lint_rfc_2383.rs:122:14
3030
|
3131
LL | #[expect(clippy::if_same_then_else)]
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3333

3434
error: this lint expectation is unfulfilled
35-
--> $DIR/expect_tool_lint_rfc_2383.rs:136:14
35+
--> $DIR/expect_tool_lint_rfc_2383.rs:128:14
3636
|
3737
LL | #[expect(clippy::overly_complex_bool_expr)]
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/rustdoc-ui/lints/expect-tool-lint-rfc-2383.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ mod rustc_ok {
2424
pub fn rustc_lints() {
2525
let x = 42.0;
2626

27-
#[expect(illegal_floating_point_literal_pattern)]
27+
#[expect(invalid_nan_comparisons)]
2828
match x {
29-
5.0 => {}
30-
6.0 => {}
29+
f32::NAN => {}
3130
_ => {}
3231
}
3332
}
@@ -40,7 +39,7 @@ mod rustc_warn {
4039
pub fn rustc_lints() {
4140
let x = 42;
4241

43-
#[expect(illegal_floating_point_literal_pattern)]
42+
#[expect(invalid_nan_comparisons)]
4443
match x {
4544
5 => {}
4645
6 => {}

tests/rustdoc-ui/lints/expect-tool-lint-rfc-2383.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ LL | #![expect(rustdoc::missing_crate_level_docs)]
77
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
88

99
warning: this lint expectation is unfulfilled
10-
--> $DIR/expect-tool-lint-rfc-2383.rs:71:14
10+
--> $DIR/expect-tool-lint-rfc-2383.rs:70:14
1111
|
1212
LL | #[expect(rustdoc::broken_intra_doc_links)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: this lint expectation is unfulfilled
16-
--> $DIR/expect-tool-lint-rfc-2383.rs:76:14
16+
--> $DIR/expect-tool-lint-rfc-2383.rs:75:14
1717
|
1818
LL | #[expect(rustdoc::invalid_html_tags)]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2020

2121
warning: this lint expectation is unfulfilled
22-
--> $DIR/expect-tool-lint-rfc-2383.rs:81:14
22+
--> $DIR/expect-tool-lint-rfc-2383.rs:80:14
2323
|
2424
LL | #[expect(rustdoc::bare_urls)]
2525
| ^^^^^^^^^^^^^^^^^^

tests/ui/array-slice-vec/vec-matching-autoslice.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// run-pass
2-
#![allow(illegal_floating_point_literal_pattern)] // FIXME #41620
32

43
pub fn main() {
54
let x = [1, 2, 3];

tests/ui/binding/match-range.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// run-pass
2-
#![allow(illegal_floating_point_literal_pattern)] // FIXME #41620
32
#![feature(exclusive_range_pattern)]
43

54
pub fn main() {

tests/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Test various non-exhaustive matches for `X..`, `..=X` and `..X` ranges.
22

33
#![feature(exclusive_range_pattern)]
4-
#![allow(illegal_floating_point_literal_pattern)]
54

65
fn main() {}
76

0 commit comments

Comments
 (0)