]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-41255.rs
Rollup merge of #53545 - FelixMcFelix:fix-50865-beta, r=petrochenkov
[rust.git] / src / test / ui / issues / issue-41255.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Matching against float literals should result in a linter error
12
13 #![feature(exclusive_range_pattern)]
14 #![allow(unused)]
15 #![forbid(illegal_floating_point_literal_pattern)]
16
17 fn main() {
18     let x = 42.0;
19     match x {
20         5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
21                    //~| WARNING hard error
22         5.0f32 => {}, //~ ERROR floating-point types cannot be used in patterns
23                       //~| WARNING hard error
24         -5.0 => {}, //~ ERROR floating-point types cannot be used in patterns
25                     //~| WARNING hard error
26         1.0 .. 33.0 => {}, //~ ERROR floating-point types cannot be used in patterns
27                            //~| WARNING hard error
28                            //~| ERROR floating-point types cannot be used in patterns
29                            //~| WARNING hard error
30         39.0 ..= 70.0 => {}, //~ ERROR floating-point types cannot be used in patterns
31                              //~| WARNING hard error
32                              //~| ERROR floating-point types cannot be used in patterns
33                              //~| WARNING hard error
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 }