diff --git a/src/librustc_mir/const_eval/_match.rs b/src/librustc_mir/const_eval/_match.rs index 3b9bbc0ba8b4..57feffbaf005 100644 --- a/src/librustc_mir/const_eval/_match.rs +++ b/src/librustc_mir/const_eval/_match.rs @@ -13,13 +13,12 @@ use self::Usefulness::*; use self::WitnessPreference::*; use rustc::middle::const_val::ConstVal; -use const_eval::eval::{compare_const_vals}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::Idx; use const_eval::pattern::{FieldPattern, Pattern, PatternKind}; -use const_eval::pattern::{PatternFoldable, PatternFolder}; +use const_eval::pattern::{PatternFoldable, PatternFolder, compare_const_vals}; use rustc::hir::def_id::DefId; use rustc::hir::RangeEnd; diff --git a/src/librustc_mir/const_eval/eval.rs b/src/librustc_mir/const_eval/eval.rs index 25a9e5223677..32f834daa4c7 100644 --- a/src/librustc_mir/const_eval/eval.rs +++ b/src/librustc_mir/const_eval/eval.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustc::middle::const_val::ConstVal::*; use rustc::middle::const_val::ConstVal; use rustc::hir::def_id::DefId; @@ -17,8 +16,6 @@ use rustc::ty::subst::Substs; use syntax::ast; -use std::cmp::Ordering; - use rustc_const_math::*; /// * `DefId` is the id of the constant. @@ -128,31 +125,3 @@ fn parse_float<'tcx>(num: &str, fty: ast::FloatTy) -> Result { ConstFloat::from_str(num, fty).map_err(|_| ()) } - -pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option { - trace!("compare_const_vals: {:?}, {:?}", a, b); - use rustc::mir::interpret::{Value, PrimVal}; - match (a, b) { - (&Value(Value::ByVal(PrimVal::Bytes(a))), - &Value(Value::ByVal(PrimVal::Bytes(b)))) => { - match ty.sty { - ty::TyFloat(ty) => { - let l = ConstFloat { - bits: a, - ty, - }; - let r = ConstFloat { - bits: b, - ty, - }; - // FIXME(oli-obk): report cmp errors? - l.try_cmp(r).ok() - }, - ty::TyInt(_) => Some((a as i128).cmp(&(b as i128))), - _ => Some(a.cmp(&b)), - } - }, - _ if a == b => Some(Ordering::Equal), - _ => None, - } -} diff --git a/src/librustc_mir/const_eval/pattern.rs b/src/librustc_mir/const_eval/pattern.rs index 0b8a96332b0f..27649146eba6 100644 --- a/src/librustc_mir/const_eval/pattern.rs +++ b/src/librustc_mir/const_eval/pattern.rs @@ -18,10 +18,10 @@ use rustc::ty::subst::{Substs, Kind}; use rustc::hir::{self, PatKind, RangeEnd}; use rustc::hir::def::{Def, CtorKind}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; -use const_eval::eval::compare_const_vals; use rustc_data_structures::indexed_vec::Idx; +use std::cmp::Ordering; use std::fmt; use syntax::ast; use syntax::ptr::P; @@ -1060,3 +1060,32 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> { } } } + +pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option { + use rustc_const_math::ConstFloat; + trace!("compare_const_vals: {:?}, {:?}", a, b); + use rustc::mir::interpret::{Value, PrimVal}; + match (a, b) { + (&ConstVal::Value(Value::ByVal(PrimVal::Bytes(a))), + &ConstVal::Value(Value::ByVal(PrimVal::Bytes(b)))) => { + match ty.sty { + ty::TyFloat(ty) => { + let l = ConstFloat { + bits: a, + ty, + }; + let r = ConstFloat { + bits: b, + ty, + }; + // FIXME(oli-obk): report cmp errors? + l.try_cmp(r).ok() + }, + ty::TyInt(_) => Some((a as i128).cmp(&(b as i128))), + _ => Some(a.cmp(&b)), + } + }, + _ if a == b => Some(Ordering::Equal), + _ => None, + } +}