diff options
Diffstat (limited to 'src/librustc_mir')
| -rw-r--r-- | src/librustc_mir/hair/pattern/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/operator.rs | 26 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 02aca73c553..6efef07ebbd 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -1115,7 +1115,12 @@ pub fn compare_const_vals<'a, 'tcx>( ty, }; // FIXME(oli-obk): report cmp errors? - l.try_cmp(r).ok() + // FIXME: Just returning Ordering::Greater here is the previous behavior but may + // not be what we want. It means that NaN > NaN is true, which if false. + match l.try_cmp(r) { + Ok(opt) => Some(opt.unwrap_or(Ordering::Greater)), + _ => None, + } }, ty::TyInt(_) => { let a = interpret::sign_extend(tcx, a, ty).expect("layout error for TyInt"); 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), |
