From d019c71df9c88c7ee19065cb6699008e55d51610 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 5 Jul 2021 17:56:43 +0200 Subject: [PATCH] Fix double warning about illegal floating-point literal pattern --- .../src/thir/pattern/const_to_pat.rs | 14 +- ...duplicate-diagnostics-2.deduplicate.stderr | 30 ---- ...deduplicate-diagnostics-2.duplicate.stderr | 39 ------ src/test/ui/deduplicate-diagnostics-2.rs | 17 --- src/test/ui/issues/issue-41255.rs | 24 ---- src/test/ui/issues/issue-41255.stderr | 132 ++---------------- src/test/ui/issues/issue-6804.rs | 4 - src/test/ui/issues/issue-6804.stderr | 22 +-- src/test/ui/lint/issue-86600-lint-twice.rs | 15 ++ .../ui/lint/issue-86600-lint-twice.stderr | 12 ++ .../match-forbidden-without-eq.rs | 2 - .../match-forbidden-without-eq.stderr | 11 +- 12 files changed, 50 insertions(+), 272 deletions(-) delete mode 100644 src/test/ui/deduplicate-diagnostics-2.deduplicate.stderr delete mode 100644 src/test/ui/deduplicate-diagnostics-2.duplicate.stderr delete mode 100644 src/test/ui/deduplicate-diagnostics-2.rs create mode 100644 src/test/ui/lint/issue-86600-lint-twice.rs create mode 100644 src/test/ui/lint/issue-86600-lint-twice.stderr diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 369fff00456a..cb9c89324d6b 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -272,12 +272,14 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> { let kind = match cv.ty.kind() { ty::Float(_) => { - tcx.struct_span_lint_hir( - lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, - id, - span, - |lint| lint.build("floating-point types cannot be used in patterns").emit(), - ); + if self.include_lint_checks { + tcx.struct_span_lint_hir( + lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, + id, + span, + |lint| lint.build("floating-point types cannot be used in patterns").emit(), + ); + } PatKind::Constant { value: cv } } ty::Adt(adt_def, _) if adt_def.is_union() => { diff --git a/src/test/ui/deduplicate-diagnostics-2.deduplicate.stderr b/src/test/ui/deduplicate-diagnostics-2.deduplicate.stderr deleted file mode 100644 index 7f6a432d5ab1..000000000000 --- a/src/test/ui/deduplicate-diagnostics-2.deduplicate.stderr +++ /dev/null @@ -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 - -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 - -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 - -warning: 3 warnings emitted - diff --git a/src/test/ui/deduplicate-diagnostics-2.duplicate.stderr b/src/test/ui/deduplicate-diagnostics-2.duplicate.stderr deleted file mode 100644 index f2315bc91ec6..000000000000 --- a/src/test/ui/deduplicate-diagnostics-2.duplicate.stderr +++ /dev/null @@ -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 - -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 - -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 - -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 - -warning: 4 warnings emitted - diff --git a/src/test/ui/deduplicate-diagnostics-2.rs b/src/test/ui/deduplicate-diagnostics-2.rs deleted file mode 100644 index f46a7c0c1c4d..000000000000 --- a/src/test/ui/deduplicate-diagnostics-2.rs +++ /dev/null @@ -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 - _ => {} - } -} diff --git a/src/test/ui/issues/issue-41255.rs b/src/test/ui/issues/issue-41255.rs index 5b95a7379135..9d7072f1665d 100644 --- a/src/test/ui/issues/issue-41255.rs +++ b/src/test/ui/issues/issue-41255.rs @@ -10,47 +10,27 @@ fn main() { match x { 5.0 => {}, //~ ERROR floating-point types cannot be used in patterns //~| 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 - //~| ERROR floating-point types cannot be used in patterns - //~| WARNING hard error //~| WARNING hard error -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 1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns //~| 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 - //~| 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 //~| ERROR floating-point types cannot be used in patterns //~| 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 ..71.0 => {} //~^ 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 ..=72.0 => {} //~^ 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 71.0.. => {} //~^ 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 _ => {}, }; @@ -58,8 +38,6 @@ fn main() { // Same for tuples match (x, 5) { (3.14, 1) => {}, //~ ERROR floating-point types cannot be used - //~| ERROR floating-point types cannot be used - //~| WARNING hard error //~| WARNING hard error _ => {}, } @@ -67,8 +45,6 @@ fn main() { struct Foo { x: f32 }; match (Foo { x }) { Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used - //~| ERROR floating-point types cannot be used - //~| WARNING hard error //~| WARNING hard error _ => {}, } diff --git a/src/test/ui/issues/issue-41255.stderr b/src/test/ui/issues/issue-41255.stderr index b6e57afcd129..bf81c8d371c0 100644 --- a/src/test/ui/issues/issue-41255.stderr +++ b/src/test/ui/issues/issue-41255.stderr @@ -13,7 +13,7 @@ LL | #![forbid(illegal_floating_point_literal_pattern)] = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:15:9 + --> $DIR/issue-41255.rs:13:9 | LL | 5.0f32 => {}, | ^^^^^^ @@ -22,7 +22,7 @@ LL | 5.0f32 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:19:10 + --> $DIR/issue-41255.rs:15:10 | LL | -5.0 => {}, | ^^^ @@ -31,7 +31,7 @@ LL | -5.0 => {}, = note: for more information, see issue #41620 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 => {}, | ^^^ @@ -40,7 +40,7 @@ LL | 1.0 .. 33.0 => {}, = note: for more information, see issue #41620 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 => {}, | ^^^^ @@ -49,7 +49,7 @@ LL | 1.0 .. 33.0 => {}, = note: for more information, see issue #41620 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 => {}, | ^^^^ @@ -58,7 +58,7 @@ LL | 39.0 ..= 70.0 => {}, = note: for more information, see issue #41620 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 => {}, | ^^^^ @@ -67,7 +67,7 @@ LL | 39.0 ..= 70.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:40:11 + --> $DIR/issue-41255.rs:26:11 | LL | ..71.0 => {} | ^^^^ @@ -76,7 +76,7 @@ LL | ..71.0 => {} = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:45:12 + --> $DIR/issue-41255.rs:29:12 | LL | ..=72.0 => {} | ^^^^ @@ -85,7 +85,7 @@ LL | ..=72.0 => {} = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:50:9 + --> $DIR/issue-41255.rs:32:9 | LL | 71.0.. => {} | ^^^^ @@ -94,7 +94,7 @@ LL | 71.0.. => {} = note: for more information, see issue #41620 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) => {}, | ^^^^ @@ -103,7 +103,7 @@ LL | (3.14, 1) => {}, = note: for more information, see issue #41620 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 } => {}, | ^^^ @@ -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! = note: for more information, see issue #41620 -error: floating-point types cannot be used in patterns - --> $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 - -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 - -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 - -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 - -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 - -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 - -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 - -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 - -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 - -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 - -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 - -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 - -error: aborting due to 24 previous errors +error: aborting due to 12 previous errors diff --git a/src/test/ui/issues/issue-6804.rs b/src/test/ui/issues/issue-6804.rs index 6d950c424e38..0260caa82cb1 100644 --- a/src/test/ui/issues/issue-6804.rs +++ b/src/test/ui/issues/issue-6804.rs @@ -9,16 +9,12 @@ fn main() { let x = NAN; match x { 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 _ => {}, }; match [x, 1.0] { [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 _ => {}, }; diff --git a/src/test/ui/issues/issue-6804.stderr b/src/test/ui/issues/issue-6804.stderr index c7411e27c255..4e2961e5e23b 100644 --- a/src/test/ui/issues/issue-6804.stderr +++ b/src/test/ui/issues/issue-6804.stderr @@ -13,7 +13,7 @@ LL | #![deny(illegal_floating_point_literal_pattern)] = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-6804.rs:19:10 + --> $DIR/issue-6804.rs:17:10 | 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! = note: for more information, see issue #41620 -error: floating-point types cannot be used in patterns - --> $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 - -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 - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/lint/issue-86600-lint-twice.rs b/src/test/ui/lint/issue-86600-lint-twice.rs new file mode 100644 index 000000000000..0e8a837d987f --- /dev/null +++ b/src/test/ui/lint/issue-86600-lint-twice.rs @@ -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 + _ => {} + } +} diff --git a/src/test/ui/lint/issue-86600-lint-twice.stderr b/src/test/ui/lint/issue-86600-lint-twice.stderr new file mode 100644 index 000000000000..8da3fb5a8394 --- /dev/null +++ b/src/test/ui/lint/issue-86600-lint-twice.stderr @@ -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 + +warning: 1 warning emitted + diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.rs b/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.rs index fa5630837b9a..59a22c33778c 100644 --- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.rs +++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.rs @@ -17,8 +17,6 @@ fn main() { match x { f32::INFINITY => { } //~^ 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 _ => { } } diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr index 9a5d57d41183..df4809dabf15 100644 --- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr +++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr @@ -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! = note: for more information, see issue #41620 -warning: floating-point types cannot be used in patterns - --> $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 - -error: aborting due to previous error; 2 warnings emitted +error: aborting due to previous error; 1 warning emitted