]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-41255.rs
Rollup merge of #42006 - jseyfried:fix_include_regression, r=nrc
[rust.git] / src / test / compile-fail / 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(slice_patterns)]
14 #![feature(exclusive_range_pattern)]
15 #![allow(unused)]
16 #![forbid(illegal_floating_point_literal_pattern)]
17
18 fn main() {
19     let x = 42.0;
20     match x {
21         5.0 => {}, //~ ERROR floating-point literals cannot be used
22                    //~| WARNING hard error
23         5.0f32 => {}, //~ ERROR floating-point literals cannot be used
24                       //~| WARNING hard error
25         -5.0 => {}, //~ ERROR floating-point literals cannot be used
26                     //~| WARNING hard error
27         1.0 .. 33.0 => {}, //~ ERROR floating-point literals cannot be used
28                            //~| WARNING hard error
29                            //~| ERROR floating-point literals cannot be used
30                            //~| WARNING hard error
31         39.0 ... 70.0 => {}, //~ ERROR floating-point literals cannot be used
32                              //~| WARNING hard error
33                              //~| ERROR floating-point literals cannot be used
34                              //~| WARNING hard error
35         _ => {},
36     };
37     let y = 5.0;
38     // Same for tuples
39     match (x, 5) {
40         (3.14, 1) => {}, //~ ERROR floating-point literals cannot be used
41                          //~| WARNING hard error
42                          //~| ERROR floating-point literals cannot be used
43                          //~| WARNING hard error
44         _ => {},
45     }
46     // Or structs
47     struct Foo { x: f32 };
48     match (Foo { x }) {
49         Foo { x: 2.0 } => {}, //~ ERROR floating-point literals cannot be used
50                               //~| WARNING hard error
51                               //~| ERROR floating-point literals cannot be used
52                               //~| WARNING hard error
53         _ => {},
54     }
55 }