Skip to content

Commit

Permalink
Auto merge of #86888 - FabianWolff:issue-86600, r=davidtwco
Browse files Browse the repository at this point in the history
Fix double warning about illegal floating-point literal pattern

This PR fixes #86600. The problem is that the `ConstToPat` struct contains a field `include_lint_checks`, which determines whether lints should be emitted or not, but this field is currently not obeyed at one point, leading to a warning being emitted more than once. I have fixed this behavior here.
  • Loading branch information
bors committed Jul 9, 2021
2 parents ee86f96 + d019c71 commit e916b7c
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 272 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down
30 changes: 0 additions & 30 deletions src/test/ui/deduplicate-diagnostics-2.deduplicate.stderr

This file was deleted.

39 changes: 0 additions & 39 deletions src/test/ui/deduplicate-diagnostics-2.duplicate.stderr

This file was deleted.

17 changes: 0 additions & 17 deletions src/test/ui/deduplicate-diagnostics-2.rs

This file was deleted.

24 changes: 0 additions & 24 deletions src/test/ui/issues/issue-41255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,41 @@ 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
_ => {},
};
let y = 5.0;
// 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
_ => {},
}
// Or structs
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
_ => {},
}
Expand Down
132 changes: 12 additions & 120 deletions src/test/ui/issues/issue-41255.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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>

error: floating-point types cannot be used in patterns
--> $DIR/issue-41255.rs:15:9
--> $DIR/issue-41255.rs:13:9
|
LL | 5.0f32 => {},
| ^^^^^^
Expand All @@ -22,7 +22,7 @@ LL | 5.0f32 => {},
= 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
--> $DIR/issue-41255.rs:15:10
|
LL | -5.0 => {},
| ^^^
Expand All @@ -31,7 +31,7 @@ LL | -5.0 => {},
= 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
--> $DIR/issue-41255.rs:17:9
|
LL | 1.0 .. 33.0 => {},
| ^^^
Expand All @@ -40,7 +40,7 @@ LL | 1.0 .. 33.0 => {},
= 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
--> $DIR/issue-41255.rs:17:16
|
LL | 1.0 .. 33.0 => {},
| ^^^^
Expand All @@ -49,7 +49,7 @@ LL | 1.0 .. 33.0 => {},
= 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
--> $DIR/issue-41255.rs:21:9
|
LL | 39.0 ..= 70.0 => {},
| ^^^^
Expand All @@ -58,7 +58,7 @@ LL | 39.0 ..= 70.0 => {},
= 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
--> $DIR/issue-41255.rs:21:18
|
LL | 39.0 ..= 70.0 => {},
| ^^^^
Expand All @@ -67,7 +67,7 @@ LL | 39.0 ..= 70.0 => {},
= 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
--> $DIR/issue-41255.rs:26:11
|
LL | ..71.0 => {}
| ^^^^
Expand All @@ -76,7 +76,7 @@ LL | ..71.0 => {}
= 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
--> $DIR/issue-41255.rs:29:12
|
LL | ..=72.0 => {}
| ^^^^
Expand All @@ -85,7 +85,7 @@ LL | ..=72.0 => {}
= 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
--> $DIR/issue-41255.rs:32:9
|
LL | 71.0.. => {}
| ^^^^
Expand All @@ -94,7 +94,7 @@ LL | 71.0.. => {}
= 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
--> $DIR/issue-41255.rs:40:10
|
LL | (3.14, 1) => {},
| ^^^^
Expand All @@ -103,121 +103,13 @@ LL | (3.14, 1) => {},
= 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
--> $DIR/issue-41255.rs:47: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: 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 </~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
error: aborting due to 12 previous errors

Loading

0 comments on commit e916b7c

Please sign in to comment.