Skip to content

Commit 38cb1fe

Browse files
Deny floating point literals in patterns
1 parent 1255053 commit 38cb1fe

6 files changed

+30
-31
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ declare_lint! {
16821682
///
16831683
/// ### Example
16841684
///
1685-
/// ```rust
1685+
/// ```rust,compile_fail
16861686
/// let x = 42.0;
16871687
///
16881688
/// match x {
@@ -1717,7 +1717,7 @@ declare_lint! {
17171717
/// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
17181718
/// [future-incompatible]: ../index.md#future-incompatible-lints
17191719
pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1720-
Warn,
1720+
Deny,
17211721
"floating-point literals cannot be used in patterns",
17221722
@future_incompatible = FutureIncompatibleInfo {
17231723
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
warning: floating-point types cannot be used in patterns
2-
--> $DIR/deduplicate-diagnostics-2.rs:7:9
1+
error: floating-point types cannot be used in patterns
2+
--> $DIR/deduplicate-diagnostics-2.rs:6:9
33
|
44
LL | 1.0 => {}
55
| ^^^
66
|
7-
= note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
7+
= note: `#[deny(illegal_floating_point_literal_pattern)]` on by default
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
1010

11-
warning: floating-point types cannot be used in patterns
12-
--> $DIR/deduplicate-diagnostics-2.rs:11:9
11+
error: floating-point types cannot be used in patterns
12+
--> $DIR/deduplicate-diagnostics-2.rs:10:9
1313
|
1414
LL | 2.0 => {}
1515
| ^^^
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1818
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
1919

20-
warning: floating-point types cannot be used in patterns
21-
--> $DIR/deduplicate-diagnostics-2.rs:7:9
20+
error: floating-point types cannot be used in patterns
21+
--> $DIR/deduplicate-diagnostics-2.rs:6:9
2222
|
2323
LL | 1.0 => {}
2424
| ^^^
2525
|
2626
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2727
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
2828

29-
warning: 3 warnings emitted
29+
error: aborting due to 3 previous errors
3030

Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
warning: floating-point types cannot be used in patterns
2-
--> $DIR/deduplicate-diagnostics-2.rs:7:9
1+
error: floating-point types cannot be used in patterns
2+
--> $DIR/deduplicate-diagnostics-2.rs:6:9
33
|
44
LL | 1.0 => {}
55
| ^^^
66
|
7-
= note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
7+
= note: `#[deny(illegal_floating_point_literal_pattern)]` on by default
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
1010

11-
warning: floating-point types cannot be used in patterns
12-
--> $DIR/deduplicate-diagnostics-2.rs:11:9
11+
error: floating-point types cannot be used in patterns
12+
--> $DIR/deduplicate-diagnostics-2.rs:10:9
1313
|
1414
LL | 2.0 => {}
1515
| ^^^
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1818
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
1919

20-
warning: floating-point types cannot be used in patterns
21-
--> $DIR/deduplicate-diagnostics-2.rs:7:9
20+
error: floating-point types cannot be used in patterns
21+
--> $DIR/deduplicate-diagnostics-2.rs:6:9
2222
|
2323
LL | 1.0 => {}
2424
| ^^^
2525
|
2626
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2727
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
2828

29-
warning: floating-point types cannot be used in patterns
30-
--> $DIR/deduplicate-diagnostics-2.rs:11:9
29+
error: floating-point types cannot be used in patterns
30+
--> $DIR/deduplicate-diagnostics-2.rs:10:9
3131
|
3232
LL | 2.0 => {}
3333
| ^^^
3434
|
3535
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3636
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
3737

38-
warning: 4 warnings emitted
38+
error: aborting due to 4 previous errors
3939

src/test/ui/deduplicate-diagnostics-2.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
// build-pass
21
// revisions: duplicate deduplicate
32
//[deduplicate] compile-flags: -Z deduplicate-diagnostics=yes
43

54
fn main() {
65
match 0.0 {
7-
1.0 => {} //~ WARNING floating-point types cannot be used in patterns
6+
1.0 => {} //~ ERROR floating-point types cannot be used in patterns
87
//~| WARNING this was previously accepted
9-
//~| WARNING floating-point types cannot be used in patterns
8+
//~| ERROR floating-point types cannot be used in patterns
109
//~| WARNING this was previously accepted
11-
2.0 => {} //~ WARNING floating-point types cannot be used in patterns
10+
2.0 => {} //~ ERROR floating-point types cannot be used in patterns
1211
//~| WARNING this was previously accepted
13-
//[duplicate]~| WARNING floating-point types cannot be used in patterns
12+
//[duplicate]~| ERROR floating-point types cannot be used in patterns
1413
//[duplicate]~| WARNING this was previously accepted
1514
_ => {}
1615
}

src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ fn main() {
1616
let x = 0.0;
1717
match x {
1818
f32::INFINITY => { }
19-
//~^ WARNING floating-point types cannot be used in patterns
19+
//~^ ERROR floating-point types cannot be used in patterns
2020
//~| WARNING will become a hard error in a future release
21-
//~| WARNING floating-point types cannot be used in patterns
21+
//~| ERROR floating-point types cannot be used in patterns
2222
//~| WARNING this was previously accepted by the compiler but is being phased out
2323
_ => { }
2424
}

src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated wit
44
LL | FOO => { }
55
| ^^^
66

7-
warning: floating-point types cannot be used in patterns
7+
error: floating-point types cannot be used in patterns
88
--> $DIR/match-forbidden-without-eq.rs:18:9
99
|
1010
LL | f32::INFINITY => { }
1111
| ^^^^^^^^^^^^^
1212
|
13-
= note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
13+
= note: `#[deny(illegal_floating_point_literal_pattern)]` on by default
1414
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1515
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
1616

17-
warning: floating-point types cannot be used in patterns
17+
error: floating-point types cannot be used in patterns
1818
--> $DIR/match-forbidden-without-eq.rs:18:9
1919
|
2020
LL | f32::INFINITY => { }
@@ -23,5 +23,5 @@ LL | f32::INFINITY => { }
2323
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2424
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
2525

26-
error: aborting due to previous error; 2 warnings emitted
26+
error: aborting due to 3 previous errors
2727

0 commit comments

Comments
 (0)