]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-41255.rs
395ab8601bcc5fb3cb50e4f81435ff941d0110c1
[rust.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 #![allow(unused)]
5 #![forbid(illegal_floating_point_literal_pattern)]
6
7 fn main() {
8     let x = 42.0;
9     match x {
10         5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
11                    //~| WARNING hard error
12         5.0f32 => {}, //~ ERROR floating-point types cannot be used in patterns
13                       //~| WARNING hard error
14         -5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
15                     //~| WARNING hard error
16         1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns
17                            //~| WARNING hard error
18                            //~| ERROR floating-point types cannot be used in patterns
19                            //~| WARNING hard error
20         39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns
21                              //~| WARNING hard error
22                              //~| ERROR floating-point types cannot be used in patterns
23                              //~| WARNING hard error
24         _ => {},
25     };
26     let y = 5.0;
27     // Same for tuples
28     match (x, 5) {
29         (3.14, 1) => {}, //~ ERROR floating-point types cannot be used
30                          //~| WARNING hard error
31         _ => {},
32     }
33     // Or structs
34     struct Foo { x: f32 };
35     match (Foo { x }) {
36         Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used
37                               //~| WARNING hard error
38         _ => {},
39     }
40 }