]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-float-classify.rs
Do not suggest `let_else` if no bindings would be introduced
[rust.git] / src / test / ui / consts / const-float-classify.rs
1 // compile-flags: -Zmir-opt-level=0
2 // run-pass
3
4 #![feature(const_float_bits_conv)]
5 #![feature(const_float_classify)]
6 #![feature(const_trait_impl)]
7
8 // Don't promote
9 const fn nop<T>(x: T) -> T { x }
10
11 macro_rules! const_assert {
12     ($a:expr, $b:expr) => {
13         {
14             const _: () = assert!($a == $b);
15             assert_eq!(nop($a), nop($b));
16         }
17     };
18 }
19
20 macro_rules! suite {
21     ( $( $tt:tt )* ) => {
22         fn f32() {
23             suite_inner!(f32 $($tt)*);
24         }
25
26         fn f64() {
27             suite_inner!(f64 $($tt)*);
28         }
29     }
30
31 }
32
33 macro_rules! suite_inner {
34     (
35         $ty:ident [$( $fn:ident ),*]
36         $val:expr => [$($out:ident),*]
37
38         $( $tail:tt )*
39     ) => {
40         $( const_assert!($ty::$fn($val), $out); )*
41         suite_inner!($ty [$($fn),*] $($tail)*)
42     };
43
44     ( $ty:ident [$( $fn:ident ),*]) => {};
45 }
46
47 #[derive(Debug)]
48 struct NonDet;
49
50 impl const PartialEq<NonDet> for bool {
51     fn eq(&self, _: &NonDet) -> bool {
52         true
53     }
54     fn ne(&self, _: &NonDet) -> bool {
55         false
56     }
57 }
58
59 // The result of the `is_sign` methods are not checked for correctness, since LLVM does not
60 // guarantee anything about the signedness of NaNs. See
61 // https://github.com/rust-lang/rust/issues/55131.
62
63 suite! {
64                    [is_nan, is_infinite, is_finite, is_normal, is_sign_positive, is_sign_negative]
65      -0.0 / 0.0 => [  true,       false,     false,     false,           NonDet,           NonDet]
66       0.0 / 0.0 => [  true,       false,     false,     false,           NonDet,           NonDet]
67             1.0 => [ false,       false,      true,      true,             true,            false]
68            -1.0 => [ false,       false,      true,      true,            false,             true]
69             0.0 => [ false,       false,      true,     false,             true,            false]
70            -0.0 => [ false,       false,      true,     false,            false,             true]
71       1.0 / 0.0 => [ false,        true,     false,     false,             true,            false]
72      -1.0 / 0.0 => [ false,        true,     false,     false,            false,             true]
73 }
74
75 fn main() {
76     f32();
77     f64();
78 }