]> git.proxmox.com Git - rustc.git/blob - src/test/ui/issues/issue-41255.rs
New upstream version 1.55.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 5.0f32 => {}, //~ ERROR floating-point types cannot be used in patterns
14 //~| WARNING hard error
15 -5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
16 //~| WARNING hard error
17 1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns
18 //~| WARNING hard error
19 //~| ERROR floating-point types cannot be used in patterns
20 //~| WARNING hard error
21 39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns
22 //~| ERROR floating-point types cannot be used in patterns
23 //~| WARNING hard error
24 //~| WARNING hard error
25
26 ..71.0 => {}
27 //~^ ERROR floating-point types cannot be used in patterns
28 //~| WARNING this was previously accepted by the compiler
29 ..=72.0 => {}
30 //~^ ERROR floating-point types cannot be used in patterns
31 //~| WARNING this was previously accepted by the compiler
32 71.0.. => {}
33 //~^ ERROR floating-point types cannot be used in patterns
34 //~| WARNING this was previously accepted by the compiler
35 _ => {},
36 };
37 let y = 5.0;
38 // Same for tuples
39 match (x, 5) {
40 (3.14, 1) => {}, //~ ERROR floating-point types cannot be used
41 //~| WARNING hard error
42 _ => {},
43 }
44 // Or structs
45 struct Foo { x: f32 };
46 match (Foo { x }) {
47 Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used
48 //~| WARNING hard error
49 _ => {},
50 }
51 }