summary refs log tree commit diff
path: root/src/librustc_mir/interpret/operator.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/librustc_mir/interpret/operator.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/librustc_mir/interpret/operator.rs')
-rw-r--r--src/librustc_mir/interpret/operator.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs
index dfc0c4a824a..e6e1ff5a53e 100644
--- a/src/librustc_mir/interpret/operator.rs
+++ b/src/librustc_mir/interpret/operator.rs
@@ -1,8 +1,9 @@
+use std::cmp::Ordering;
+
 use rustc::mir;
 use rustc::ty::{self, Ty};
 use rustc_const_math::ConstFloat;
 use syntax::ast::FloatTy;
-use std::cmp::Ordering;
 use rustc::ty::layout::LayoutOf;
 
 use super::{EvalContext, Place, Machine, ValTy};
@@ -134,13 +135,24 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
                 bits: r,
                 ty,
             };
+            let cmp = |l: ConstFloat, r: ConstFloat| -> Option<Ordering> {
+                l.try_cmp(r).unwrap_or(None)
+            };
             match op {
-                Eq => PrimVal::from_bool(l.try_cmp(r).unwrap() == Ordering::Equal),
-                Ne => PrimVal::from_bool(l.try_cmp(r).unwrap() != Ordering::Equal),
-                Lt => PrimVal::from_bool(l.try_cmp(r).unwrap() == Ordering::Less),
-                Le => PrimVal::from_bool(l.try_cmp(r).unwrap() != Ordering::Greater),
-                Gt => PrimVal::from_bool(l.try_cmp(r).unwrap() == Ordering::Greater),
-                Ge => PrimVal::from_bool(l.try_cmp(r).unwrap() != Ordering::Less),
+                Eq => PrimVal::from_bool(cmp(l, r) == Some(Ordering::Equal)),
+                Ne => PrimVal::from_bool(cmp(l, r) != Some(Ordering::Equal)),
+                Lt => PrimVal::from_bool(cmp(l, r) == Some(Ordering::Less)),
+                Gt => PrimVal::from_bool(cmp(l, r) == Some(Ordering::Greater)),
+                Le => PrimVal::from_bool(match cmp(l, r) {
+                    Some(Ordering::Less) => true,
+                    Some(Ordering::Equal) => true,
+                    _ => false,
+                }),
+                Ge => PrimVal::from_bool(match cmp(l, r) {
+                    Some(Ordering::Greater) => true,
+                    Some(Ordering::Equal) => true,
+                    _ => false,
+                }),
                 Add => PrimVal::Bytes((l + r).unwrap().bits),
                 Sub => PrimVal::Bytes((l - r).unwrap().bits),
                 Mul => PrimVal::Bytes((l * r).unwrap().bits),