]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-50811.rs
Enable full revision in const generics ui tests
[rust.git] / src / test / ui / issues / issue-50811.rs
1 // run-pass
2 #![feature(test)]
3
4 extern crate test;
5
6 use std::mem::size_of;
7 use test::black_box;
8
9 // Ensure the const-eval result and runtime result of float comparison are equivalent.
10
11 macro_rules! compare {
12     ($op:tt) => {
13         compare!(
14             [f64::NEG_INFINITY, -f64::MAX, -1.0, -0.0, 0.0, 1.0, f64::MAX, f64::INFINITY, f64::NAN],
15             $op
16         );
17     };
18     ([$($lhs:expr),+], $op:tt) => {
19         $(compare!(
20             $lhs,
21             $op,
22             [f64::NEG_INFINITY, -f64::MAX, -1.0, -0.0, 0.0, 1.0, f64::MAX, f64::INFINITY, f64::NAN]
23         );)+
24     };
25     ($lhs:expr, $op:tt, [$($rhs:expr),+]) => {
26         $({
27             // Wrap the check in its own function to reduce time needed to borrowck.
28             fn check() {
29                 static CONST_EVAL: bool = $lhs $op $rhs;
30                 let runtime_eval = black_box($lhs) $op black_box($rhs);
31                 assert_eq!(CONST_EVAL, runtime_eval, stringify!($lhs $op $rhs));
32                 assert_eq!(
33                     size_of::<[u8; ($lhs $op $rhs) as usize]>(),
34                     runtime_eval as usize,
35                     stringify!($lhs $op $rhs (forced const eval))
36                 );
37             }
38             check();
39         })+
40     };
41 }
42
43 fn main() {
44     assert_eq!(0.0/0.0 < 0.0/0.0, false);
45     assert_eq!(0.0/0.0 > 0.0/0.0, false);
46     assert_eq!(f64::NAN < f64::NAN, false);
47     assert_eq!(f64::NAN > f64::NAN, false);
48
49     compare!(==);
50     compare!(!=);
51     compare!(<);
52     compare!(<=);
53     compare!(>);
54     compare!(>=);
55 }