diff options
| author | Oliver Schneider <git-no-reply-9879165716479413131@oli-obk.de> | 2018-01-26 15:27:38 +0100 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2018-03-08 08:34:11 +0100 |
| commit | 0e2da01b91b991da398e4a7a4e4906fc2b31a704 (patch) | |
| tree | 4c1d9e99bdf9ce47b8857686f312bbdbcef7cbc9 /src | |
| parent | b75a828e2ba5a3fc7b433bc0898cba3596758fe6 (diff) | |
| download | rust-0e2da01b91b991da398e4a7a4e4906fc2b31a704.tar.gz rust-0e2da01b91b991da398e4a7a4e4906fc2b31a704.zip | |
Move compare_const_vals out of `eval`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/const_eval/_match.rs | 3 | ||||
| -rw-r--r-- | src/librustc_mir/const_eval/eval.rs | 31 | ||||
| -rw-r--r-- | src/librustc_mir/const_eval/pattern.rs | 31 |
3 files changed, 31 insertions, 34 deletions
diff --git a/src/librustc_mir/const_eval/_match.rs b/src/librustc_mir/const_eval/_match.rs index 3b9bbc0ba8b..57feffbaf00 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 25a9e522367..32f834daa4c 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, ()> { ConstFloat::from_str(num, fty).map_err(|_| ()) } - -pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option<Ordering> { - 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 0b8a96332b0..27649146eba 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<Ordering> { + 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, + } +} |
