]> git.lizzy.rs Git - rust.git/blob - tests/ui/match/issue-41255.rs
Rollup merge of #107074 - lcnr:validate-dont-skip-opaque, r=compiler-errors
[rust.git] / tests / ui / match / 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                              //~| ERROR floating-point types cannot be used in patterns
22                              //~| WARNING hard error
23                              //~| WARNING hard error
24
25         ..71.0 => {}
26         //~^ ERROR floating-point types cannot be used in patterns
27         //~| WARNING this was previously accepted by the compiler
28         ..=72.0 => {}
29         //~^ ERROR floating-point types cannot be used in patterns
30         //~| WARNING this was previously accepted by the compiler
31         71.0.. => {}
32         //~^ ERROR floating-point types cannot be used in patterns
33         //~| WARNING this was previously accepted by the compiler
34         _ => {},
35     };
36     let y = 5.0;
37     // Same for tuples
38     match (x, 5) {
39         (3.14, 1) => {}, //~ ERROR floating-point types cannot be used
40                          //~| WARNING hard error
41         _ => {},
42     }
43     // Or structs
44     struct Foo { x: f32 };
45     match (Foo { x }) {
46         Foo { x: 2.0 } => {}, //~ ERROR floating-point types cannot be used
47                               //~| WARNING hard error
48         _ => {},
49     }
50 }