summary refs log tree commit diff
path: root/src/test/run-pass/issue-50811.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-05-25 18:30:06 +0000
committerbors <bors@rust-lang.org>2018-05-25 18:30:06 +0000
commit827013a31b88e536e85b8e6ceb5b9988042ec335 (patch)
tree2f4527603327f3996eb42813cae163caa0296f70 /src/test/run-pass/issue-50811.rs
parenta7756804103447ea4e68a71ccf071e7ad8f7a03e (diff)
parentb3785a31cdae1c164504db6da9c0f8fe6834d4c3 (diff)
downloadrust-1.26.1.tar.gz
rust-1.26.1.zip
Auto merge of #51045 - Mark-Simulacrum:stable-point, r=alexcrichton 1.26.1
Stable point release (1.26.1)

This includes all items on [the wishlist](https://github.com/rust-lang/rust/issues/50756), plus https://github.com/rust-lang/rust/pull/50694, which backported cleanly.

The target date is May 29th, Tuesday next week.

cc @rust-lang/compiler @oli-obk @eddyb  -- I backported https://github.com/rust-lang/rust/pull/50812, but it wasn't a clean patch so review would be appreciated.
Diffstat (limited to 'src/test/run-pass/issue-50811.rs')
-rw-r--r--src/test/run-pass/issue-50811.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/run-pass/issue-50811.rs b/src/test/run-pass/issue-50811.rs
new file mode 100644
index 00000000000..05b168d98f1
--- /dev/null
+++ b/src/test/run-pass/issue-50811.rs
@@ -0,0 +1,65 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(test)]
+
+extern crate test;
+
+use std::f64::{NAN, NEG_INFINITY, INFINITY, MAX};
+use std::mem::size_of;
+use test::black_box;
+
+// Ensure the const-eval result and runtime result of float comparison are equivalent.
+
+macro_rules! compare {
+    ($op:tt) => {
+        compare!(
+            [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN],
+            $op
+        );
+    };
+    ([$($lhs:expr),+], $op:tt) => {
+        $(compare!(
+            $lhs,
+            $op,
+            [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN]
+        );)+
+    };
+    ($lhs:expr, $op:tt, [$($rhs:expr),+]) => {
+        $({
+            // Wrap the check in its own function to reduce time needed to borrowck.
+            fn check() {
+                static CONST_EVAL: bool = $lhs $op $rhs;
+                let runtime_eval = black_box($lhs) $op black_box($rhs);
+                assert_eq!(CONST_EVAL, runtime_eval, stringify!($lhs $op $rhs));
+                assert_eq!(
+                    size_of::<[u8; ($lhs $op $rhs) as usize]>(),
+                    runtime_eval as usize,
+                    stringify!($lhs $op $rhs (forced const eval))
+                );
+            }
+            check();
+        })+
+    };
+}
+
+fn main() {
+    assert_eq!(0.0/0.0 < 0.0/0.0, false);
+    assert_eq!(0.0/0.0 > 0.0/0.0, false);
+    assert_eq!(NAN < NAN, false);
+    assert_eq!(NAN > NAN, false);
+
+    compare!(==);
+    compare!(!=);
+    compare!(<);
+    compare!(<=);
+    compare!(>);
+    compare!(>=);
+}