Fix double warning about illegal floating-point literal pattern

This commit is contained in:
Fabian Wolff 2021-07-05 17:56:43 +02:00
parent 5249414809
commit d019c71df9
12 changed files with 50 additions and 272 deletions

View File

@ -272,12 +272,14 @@ fn recur(
let kind = match cv.ty.kind() { let kind = match cv.ty.kind() {
ty::Float(_) => { ty::Float(_) => {
tcx.struct_span_lint_hir( if self.include_lint_checks {
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, tcx.struct_span_lint_hir(
id, lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
span, id,
|lint| lint.build("floating-point types cannot be used in patterns").emit(), span,
); |lint| lint.build("floating-point types cannot be used in patterns").emit(),
);
}
PatKind::Constant { value: cv } PatKind::Constant { value: cv }
} }
ty::Adt(adt_def, _) if adt_def.is_union() => { ty::Adt(adt_def, _) if adt_def.is_union() => {

View File

@ -1,30 +0,0 @@
warning: floating-point types cannot be used in patterns
--> $DIR/deduplicate-diagnostics-2.rs:7:9
|
LL | 1.0 => {}
| ^^^
|
= note: `#[warn(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
|
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
|
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

View File

@ -1,39 +0,0 @@
warning: floating-point types cannot be used in patterns
--> $DIR/deduplicate-diagnostics-2.rs:7:9
|
LL | 1.0 => {}
| ^^^
|
= note: `#[warn(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
|
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
|
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
|
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

View File

@ -1,17 +0,0 @@
// 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
//~| WARNING this was previously accepted
//~| WARNING floating-point types cannot be used in patterns
//~| WARNING this was previously accepted
2.0 => {} //~ WARNING floating-point types cannot be used in patterns
//~| WARNING this was previously accepted
//[duplicate]~| WARNING floating-point types cannot be used in patterns
//[duplicate]~| WARNING this was previously accepted
_ => {}
}
}

View File

@ -10,47 +10,27 @@ fn main() {
match x { match x {
5.0 => {}, //~ ERROR floating-point types cannot be used in patterns 5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
//~| WARNING hard error //~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING this was previously accepted by the compiler but is being
5.0f32 => {}, //~ ERROR floating-point types cannot be used in patterns 5.0f32 => {}, //~ ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| WARNING hard error //~| WARNING hard error
-5.0 => {}, //~ ERROR floating-point types cannot be used in patterns -5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| WARNING hard error //~| WARNING hard error
1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns 1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns
//~| WARNING hard error //~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns //~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error //~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns 39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns //~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error //~| WARNING hard error
//~| ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| WARNING hard error
//~| WARNING hard error //~| WARNING hard error
..71.0 => {} ..71.0 => {}
//~^ ERROR floating-point types cannot be used in patterns //~^ ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| WARNING this was previously accepted by the compiler //~| WARNING this was previously accepted by the compiler
..=72.0 => {} ..=72.0 => {}
//~^ ERROR floating-point types cannot be used in patterns //~^ ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| WARNING this was previously accepted by the compiler //~| WARNING this was previously accepted by the compiler
71.0.. => {} 71.0.. => {}
//~^ ERROR floating-point types cannot be used in patterns //~^ ERROR floating-point types cannot be used in patterns
//~| ERROR floating-point types cannot be used in patterns
//~| WARNING hard error
//~| WARNING this was previously accepted by the compiler //~| WARNING this was previously accepted by the compiler
_ => {}, _ => {},
}; };
@ -58,8 +38,6 @@ fn main() {
// Same for tuples // Same for tuples
match (x, 5) { match (x, 5) {
(3.14, 1) => {}, //~ ERROR floating-point types cannot be used (3.14, 1) => {}, //~ ERROR floating-point types cannot be used
//~| ERROR floating-point types cannot be used
//~| WARNING hard error
//~| WARNING hard error //~| WARNING hard error
_ => {}, _ => {},
} }
@ -67,8 +45,6 @@ fn main() {
struct Foo { x: f32 }; struct Foo { x: f32 };
match (Foo { x }) { match (Foo { x }) {
Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used
//~| ERROR floating-point types cannot be used
//~| WARNING hard error
//~| WARNING hard error //~| WARNING hard error
_ => {}, _ => {},
} }

View File

@ -13,7 +13,7 @@ LL | #![forbid(illegal_floating_point_literal_pattern)]
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:15:9 --> $DIR/issue-41255.rs:13:9
| |
LL | 5.0f32 => {}, LL | 5.0f32 => {},
| ^^^^^^ | ^^^^^^
@ -22,7 +22,7 @@ LL | 5.0f32 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:19:10 --> $DIR/issue-41255.rs:15:10
| |
LL | -5.0 => {}, LL | -5.0 => {},
| ^^^ | ^^^
@ -31,7 +31,7 @@ LL | -5.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:23:9 --> $DIR/issue-41255.rs:17:9
| |
LL | 1.0 .. 33.0 => {}, LL | 1.0 .. 33.0 => {},
| ^^^ | ^^^
@ -40,7 +40,7 @@ LL | 1.0 .. 33.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:23:16 --> $DIR/issue-41255.rs:17:16
| |
LL | 1.0 .. 33.0 => {}, LL | 1.0 .. 33.0 => {},
| ^^^^ | ^^^^
@ -49,7 +49,7 @@ LL | 1.0 .. 33.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:31:9 --> $DIR/issue-41255.rs:21:9
| |
LL | 39.0 ..= 70.0 => {}, LL | 39.0 ..= 70.0 => {},
| ^^^^ | ^^^^
@ -58,7 +58,7 @@ LL | 39.0 ..= 70.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:31:18 --> $DIR/issue-41255.rs:21:18
| |
LL | 39.0 ..= 70.0 => {}, LL | 39.0 ..= 70.0 => {},
| ^^^^ | ^^^^
@ -67,7 +67,7 @@ LL | 39.0 ..= 70.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:40:11 --> $DIR/issue-41255.rs:26:11
| |
LL | ..71.0 => {} LL | ..71.0 => {}
| ^^^^ | ^^^^
@ -76,7 +76,7 @@ LL | ..71.0 => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:45:12 --> $DIR/issue-41255.rs:29:12
| |
LL | ..=72.0 => {} LL | ..=72.0 => {}
| ^^^^ | ^^^^
@ -85,7 +85,7 @@ LL | ..=72.0 => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:50:9 --> $DIR/issue-41255.rs:32:9
| |
LL | 71.0.. => {} LL | 71.0.. => {}
| ^^^^ | ^^^^
@ -94,7 +94,7 @@ LL | 71.0.. => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:60:10 --> $DIR/issue-41255.rs:40:10
| |
LL | (3.14, 1) => {}, LL | (3.14, 1) => {},
| ^^^^ | ^^^^
@ -103,7 +103,7 @@ LL | (3.14, 1) => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:69:18 --> $DIR/issue-41255.rs:47:18
| |
LL | Foo { x: 2.0 } => {}, LL | Foo { x: 2.0 } => {},
| ^^^ | ^^^
@ -111,113 +111,5 @@ LL | Foo { x: 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! = 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> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: aborting due to 12 previous errors
--> $DIR/issue-41255.rs:11:9
|
LL | 5.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:15:9
|
LL | 5.0f32 => {},
| ^^^^^^
|
= 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: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:19:10
|
LL | -5.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:23:9
|
LL | 1.0 .. 33.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:23:16
|
LL | 1.0 .. 33.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:31:9
|
LL | 39.0 ..= 70.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:31:18
|
LL | 39.0 ..= 70.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:40:11
|
LL | ..71.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:45:12
|
LL | ..=72.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:50:9
|
LL | 71.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>
error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:60:10
|
LL | (3.14, 1) => {},
| ^^^^
|
= 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: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:69:18
|
LL | Foo { x: 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>
error: aborting due to 24 previous errors

View File

@ -9,16 +9,12 @@ fn main() {
let x = NAN; let x = NAN;
match x { match x {
NAN => {}, //~ ERROR floating-point types cannot be used NAN => {}, //~ ERROR floating-point types cannot be used
//~^ WARN this was previously accepted by the compiler but is being phased out
//~| ERROR floating-point types cannot be used in patterns
//~| WARN this was previously accepted by the compiler but is being phased out //~| WARN this was previously accepted by the compiler but is being phased out
_ => {}, _ => {},
}; };
match [x, 1.0] { match [x, 1.0] {
[NAN, _] => {}, //~ ERROR floating-point types cannot be used [NAN, _] => {}, //~ ERROR floating-point types cannot be used
//~| ERROR floating-point types cannot be used
//~| WARN this was previously accepted by the compiler but is being phased out
//~| WARN this was previously accepted by the compiler but is being phased out //~| WARN this was previously accepted by the compiler but is being phased out
_ => {}, _ => {},
}; };

View File

@ -13,7 +13,7 @@ LL | #![deny(illegal_floating_point_literal_pattern)]
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: floating-point types cannot be used in patterns
--> $DIR/issue-6804.rs:19:10 --> $DIR/issue-6804.rs:17:10
| |
LL | [NAN, _] => {}, LL | [NAN, _] => {},
| ^^^ | ^^^
@ -21,23 +21,5 @@ LL | [NAN, _] => {},
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = 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> = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns error: aborting due to 2 previous errors
--> $DIR/issue-6804.rs:11:9
|
LL | NAN => {},
| ^^^
|
= 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: floating-point types cannot be used in patterns
--> $DIR/issue-6804.rs:19:10
|
LL | [NAN, _] => {},
| ^^^
|
= 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 4 previous errors

View File

@ -0,0 +1,15 @@
// Regression test for #86600, where an instance of the
// `illegal_floating_point_literal_pattern` lint was issued twice.
// check-pass
fn main() {
let x = 42.0;
match x {
5.0 => {}
//~^ WARNING: floating-point types cannot be used in patterns
//~| WARNING: this was previously accepted by the compiler
_ => {}
}
}

View File

@ -0,0 +1,12 @@
warning: floating-point types cannot be used in patterns
--> $DIR/issue-86600-lint-twice.rs:10:9
|
LL | 5.0 => {}
| ^^^
|
= note: `#[warn(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: 1 warning emitted

View File

@ -17,8 +17,6 @@ fn main() {
match x { match x {
f32::INFINITY => { } f32::INFINITY => { }
//~^ WARNING floating-point types cannot be used in patterns //~^ WARNING 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
//~| WARNING this was previously accepted by the compiler but is being phased out //~| WARNING this was previously accepted by the compiler but is being phased out
_ => { } _ => { }
} }

View File

@ -14,14 +14,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! = 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> = 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: aborting due to previous error; 1 warning emitted
--> $DIR/match-forbidden-without-eq.rs:18:9
|
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