]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-41255.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-41255.rs
1 // Matching against float literals should result in a linter error
2
3 #![feature(exclusive_range_pattern)]
4 #![feature(half_open_range_patterns)]
5 #![allow(unused)]
6 #![forbid(illegal_floating_point_literal_pattern)]
7
8 fn main() {
9 let x = 42.0;
10 match x {
11 5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
12 //~| 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
15 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
18 //~| WARNING hard error
19 -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
22 //~| WARNING hard error
23 1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns
24 //~| WARNING hard error
25 //~| ERROR floating-point types cannot be used in patterns
26 //~| 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
31 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
35 //~| ERROR floating-point types cannot be used in patterns
36 //~| WARNING hard error
37 //~| WARNING hard error
38 //~| WARNING hard error
39
40 ..71.0 => {}
41 //~^ ERROR floating-point types cannot be used in patterns
42 //~| ERROR floating-point types cannot be used in patterns
43 //~| WARNING hard error
44 //~| WARNING this was previously accepted by the compiler
45 ..=72.0 => {}
46 //~^ ERROR floating-point types cannot be used in patterns
47 //~| ERROR floating-point types cannot be used in patterns
48 //~| WARNING hard error
49 //~| WARNING this was previously accepted by the compiler
50 71.0.. => {}
51 //~^ ERROR floating-point types cannot be used in patterns
52 //~| ERROR floating-point types cannot be used in patterns
53 //~| WARNING hard error
54 //~| WARNING this was previously accepted by the compiler
55 _ => {},
56 };
57 let y = 5.0;
58 // Same for tuples
59 match (x, 5) {
60 (3.14, 1) => {}, //~ ERROR floating-point types cannot be used
61 //~| ERROR floating-point types cannot be used
62 //~| WARNING hard error
63 //~| WARNING hard error
64 _ => {},
65 }
66 // Or structs
67 struct Foo { x: f32 };
68 match (Foo { x }) {
69 Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used
70 //~| ERROR floating-point types cannot be used
71 //~| WARNING hard error
72 //~| WARNING hard error
73 _ => {},
74 }
75 }