Skip to content

Commit d019c71

Browse files
committed
Fix double warning about illegal floating-point literal pattern
1 parent 5249414 commit d019c71

12 files changed

+50
-272
lines changed

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,14 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
272272

273273
let kind = match cv.ty.kind() {
274274
ty::Float(_) => {
275-
tcx.struct_span_lint_hir(
276-
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
277-
id,
278-
span,
279-
|lint| lint.build("floating-point types cannot be used in patterns").emit(),
280-
);
275+
if self.include_lint_checks {
276+
tcx.struct_span_lint_hir(
277+
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
278+
id,
279+
span,
280+
|lint| lint.build("floating-point types cannot be used in patterns").emit(),
281+
);
282+
}
281283
PatKind::Constant { value: cv }
282284
}
283285
ty::Adt(adt_def, _) if adt_def.is_union() => {

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

-30
This file was deleted.

src/test/ui/deduplicate-diagnostics-2.duplicate.stderr

-39
This file was deleted.

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

-17
This file was deleted.

src/test/ui/issues/issue-41255.rs

-24
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,41 @@ fn main() {
1010
match x {
1111
5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
1212
//~| WARNING hard error
13-
//~| ERROR floating-point types cannot be used in patterns
14-
//~| WARNING this was previously accepted by the compiler but is being
1513
5.0f32 => {}, //~ ERROR floating-point types cannot be used in patterns
16-
//~| ERROR floating-point types cannot be used in patterns
17-
//~| WARNING hard error
1814
//~| WARNING hard error
1915
-5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
20-
//~| ERROR floating-point types cannot be used in patterns
21-
//~| WARNING hard error
2216
//~| WARNING hard error
2317
1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns
2418
//~| WARNING hard error
2519
//~| ERROR floating-point types cannot be used in patterns
2620
//~| WARNING hard error
27-
//~| ERROR floating-point types cannot be used in patterns
28-
//~| WARNING hard error
29-
//~| ERROR floating-point types cannot be used in patterns
30-
//~| WARNING hard error
3121
39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns
32-
//~| ERROR floating-point types cannot be used in patterns
33-
//~| WARNING hard error
34-
//~| ERROR floating-point types cannot be used in patterns
3522
//~| ERROR floating-point types cannot be used in patterns
3623
//~| WARNING hard error
3724
//~| WARNING hard error
38-
//~| WARNING hard error
3925

4026
..71.0 => {}
4127
//~^ ERROR floating-point types cannot be used in patterns
42-
//~| ERROR floating-point types cannot be used in patterns
43-
//~| WARNING hard error
4428
//~| WARNING this was previously accepted by the compiler
4529
..=72.0 => {}
4630
//~^ ERROR floating-point types cannot be used in patterns
47-
//~| ERROR floating-point types cannot be used in patterns
48-
//~| WARNING hard error
4931
//~| WARNING this was previously accepted by the compiler
5032
71.0.. => {}
5133
//~^ ERROR floating-point types cannot be used in patterns
52-
//~| ERROR floating-point types cannot be used in patterns
53-
//~| WARNING hard error
5434
//~| WARNING this was previously accepted by the compiler
5535
_ => {},
5636
};
5737
let y = 5.0;
5838
// Same for tuples
5939
match (x, 5) {
6040
(3.14, 1) => {}, //~ ERROR floating-point types cannot be used
61-
//~| ERROR floating-point types cannot be used
62-
//~| WARNING hard error
6341
//~| WARNING hard error
6442
_ => {},
6543
}
6644
// Or structs
6745
struct Foo { x: f32 };
6846
match (Foo { x }) {
6947
Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used
70-
//~| ERROR floating-point types cannot be used
71-
//~| WARNING hard error
7248
//~| WARNING hard error
7349
_ => {},
7450
}

src/test/ui/issues/issue-41255.stderr

+12-120
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![forbid(illegal_floating_point_literal_pattern)]
1313
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
1414

1515
error: floating-point types cannot be used in patterns
16-
--> $DIR/issue-41255.rs:15:9
16+
--> $DIR/issue-41255.rs:13:9
1717
|
1818
LL | 5.0f32 => {},
1919
| ^^^^^^
@@ -22,7 +22,7 @@ LL | 5.0f32 => {},
2222
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
2323

2424
error: floating-point types cannot be used in patterns
25-
--> $DIR/issue-41255.rs:19:10
25+
--> $DIR/issue-41255.rs:15:10
2626
|
2727
LL | -5.0 => {},
2828
| ^^^
@@ -31,7 +31,7 @@ LL | -5.0 => {},
3131
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
3232

3333
error: floating-point types cannot be used in patterns
34-
--> $DIR/issue-41255.rs:23:9
34+
--> $DIR/issue-41255.rs:17:9
3535
|
3636
LL | 1.0 .. 33.0 => {},
3737
| ^^^
@@ -40,7 +40,7 @@ LL | 1.0 .. 33.0 => {},
4040
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
4141

4242
error: floating-point types cannot be used in patterns
43-
--> $DIR/issue-41255.rs:23:16
43+
--> $DIR/issue-41255.rs:17:16
4444
|
4545
LL | 1.0 .. 33.0 => {},
4646
| ^^^^
@@ -49,7 +49,7 @@ LL | 1.0 .. 33.0 => {},
4949
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
5050

5151
error: floating-point types cannot be used in patterns
52-
--> $DIR/issue-41255.rs:31:9
52+
--> $DIR/issue-41255.rs:21:9
5353
|
5454
LL | 39.0 ..= 70.0 => {},
5555
| ^^^^
@@ -58,7 +58,7 @@ LL | 39.0 ..= 70.0 => {},
5858
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
5959

6060
error: floating-point types cannot be used in patterns
61-
--> $DIR/issue-41255.rs:31:18
61+
--> $DIR/issue-41255.rs:21:18
6262
|
6363
LL | 39.0 ..= 70.0 => {},
6464
| ^^^^
@@ -67,7 +67,7 @@ LL | 39.0 ..= 70.0 => {},
6767
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
6868

6969
error: floating-point types cannot be used in patterns
70-
--> $DIR/issue-41255.rs:40:11
70+
--> $DIR/issue-41255.rs:26:11
7171
|
7272
LL | ..71.0 => {}
7373
| ^^^^
@@ -76,7 +76,7 @@ LL | ..71.0 => {}
7676
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
7777

7878
error: floating-point types cannot be used in patterns
79-
--> $DIR/issue-41255.rs:45:12
79+
--> $DIR/issue-41255.rs:29:12
8080
|
8181
LL | ..=72.0 => {}
8282
| ^^^^
@@ -85,7 +85,7 @@ LL | ..=72.0 => {}
8585
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
8686

8787
error: floating-point types cannot be used in patterns
88-
--> $DIR/issue-41255.rs:50:9
88+
--> $DIR/issue-41255.rs:32:9
8989
|
9090
LL | 71.0.. => {}
9191
| ^^^^
@@ -94,7 +94,7 @@ LL | 71.0.. => {}
9494
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
9595

9696
error: floating-point types cannot be used in patterns
97-
--> $DIR/issue-41255.rs:60:10
97+
--> $DIR/issue-41255.rs:40:10
9898
|
9999
LL | (3.14, 1) => {},
100100
| ^^^^
@@ -103,121 +103,13 @@ LL | (3.14, 1) => {},
103103
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
104104

105105
error: floating-point types cannot be used in patterns
106-
--> $DIR/issue-41255.rs:69:18
106+
--> $DIR/issue-41255.rs:47:18
107107
|
108108
LL | Foo { x: 2.0 } => {},
109109
| ^^^
110110
|
111111
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
112112
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
113113

114-
error: floating-point types cannot be used in patterns
115-
--> $DIR/issue-41255.rs:11:9
116-
|
117-
LL | 5.0 => {},
118-
| ^^^
119-
|
120-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
121-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
122-
123-
error: floating-point types cannot be used in patterns
124-
--> $DIR/issue-41255.rs:15:9
125-
|
126-
LL | 5.0f32 => {},
127-
| ^^^^^^
128-
|
129-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
130-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
131-
132-
error: floating-point types cannot be used in patterns
133-
--> $DIR/issue-41255.rs:19:10
134-
|
135-
LL | -5.0 => {},
136-
| ^^^
137-
|
138-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
139-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
140-
141-
error: floating-point types cannot be used in patterns
142-
--> $DIR/issue-41255.rs:23:9
143-
|
144-
LL | 1.0 .. 33.0 => {},
145-
| ^^^
146-
|
147-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
148-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
149-
150-
error: floating-point types cannot be used in patterns
151-
--> $DIR/issue-41255.rs:23:16
152-
|
153-
LL | 1.0 .. 33.0 => {},
154-
| ^^^^
155-
|
156-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
157-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
158-
159-
error: floating-point types cannot be used in patterns
160-
--> $DIR/issue-41255.rs:31:9
161-
|
162-
LL | 39.0 ..= 70.0 => {},
163-
| ^^^^
164-
|
165-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
166-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
167-
168-
error: floating-point types cannot be used in patterns
169-
--> $DIR/issue-41255.rs:31:18
170-
|
171-
LL | 39.0 ..= 70.0 => {},
172-
| ^^^^
173-
|
174-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
175-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
176-
177-
error: floating-point types cannot be used in patterns
178-
--> $DIR/issue-41255.rs:40:11
179-
|
180-
LL | ..71.0 => {}
181-
| ^^^^
182-
|
183-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
184-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
185-
186-
error: floating-point types cannot be used in patterns
187-
--> $DIR/issue-41255.rs:45:12
188-
|
189-
LL | ..=72.0 => {}
190-
| ^^^^
191-
|
192-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
193-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
194-
195-
error: floating-point types cannot be used in patterns
196-
--> $DIR/issue-41255.rs:50:9
197-
|
198-
LL | 71.0.. => {}
199-
| ^^^^
200-
|
201-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
202-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
203-
204-
error: floating-point types cannot be used in patterns
205-
--> $DIR/issue-41255.rs:60:10
206-
|
207-
LL | (3.14, 1) => {},
208-
| ^^^^
209-
|
210-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
211-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
212-
213-
error: floating-point types cannot be used in patterns
214-
--> $DIR/issue-41255.rs:69:18
215-
|
216-
LL | Foo { x: 2.0 } => {},
217-
| ^^^
218-
|
219-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220-
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
221-
222-
error: aborting due to 24 previous errors
114+
error: aborting due to 12 previous errors
223115

0 commit comments

Comments
 (0)