Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny float matches #84045

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ declare_lint! {
///
/// ### Example
///
/// ```rust
/// ```rust,compile_fail
/// let x = 42.0;
///
/// match x {
Expand Down Expand Up @@ -1717,7 +1717,7 @@ declare_lint! {
/// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
Warn,
Deny,
"floating-point literals cannot be used in patterns",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/deduplicate-diagnostics-2.deduplicate.stderr
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
warning: floating-point types cannot be used in patterns
--> $DIR/deduplicate-diagnostics-2.rs:7:9
error: floating-point types cannot be used in patterns
--> $DIR/deduplicate-diagnostics-2.rs:6:9
|
LL | 1.0 => {}
| ^^^
|
= note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
= note: `#[deny(illegal_floating_point_literal_pattern)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>

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

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

warning: 3 warnings emitted
error: aborting due to 3 previous errors

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

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

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

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

warning: 4 warnings emitted
error: aborting due to 4 previous errors

9 changes: 4 additions & 5 deletions src/test/ui/deduplicate-diagnostics-2.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// build-pass
// revisions: duplicate deduplicate
//[deduplicate] compile-flags: -Z deduplicate-diagnostics=yes

fn main() {
match 0.0 {
1.0 => {} //~ WARNING floating-point types cannot be used in patterns
1.0 => {} //~ ERROR floating-point types cannot be used in patterns
//~| WARNING this was previously accepted
//~| WARNING floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING this was previously accepted
2.0 => {} //~ WARNING floating-point types cannot be used in patterns
2.0 => {} //~ ERROR floating-point types cannot be used in patterns
//~| WARNING this was previously accepted
//[duplicate]~| WARNING floating-point types cannot be used in patterns
//[duplicate]~| ERROR floating-point types cannot be used in patterns
//[duplicate]~| WARNING this was previously accepted
_ => {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn main() {
let x = 0.0;
match x {
f32::INFINITY => { }
//~^ WARNING floating-point types cannot be used in patterns
//~^ ERROR floating-point types cannot be used in patterns
//~| WARNING will become a hard error in a future release
//~| WARNING floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING this was previously accepted by the compiler but is being phased out
_ => { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated wit
LL | FOO => { }
| ^^^

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

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

error: aborting due to previous error; 2 warnings emitted
error: aborting due to 3 previous errors