]> git.lizzy.rs Git - rust.git/commitdiff
Move compare_const_vals out of `eval`
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Fri, 26 Jan 2018 14:27:38 +0000 (15:27 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 8 Mar 2018 07:34:11 +0000 (08:34 +0100)
src/librustc_mir/const_eval/_match.rs
src/librustc_mir/const_eval/eval.rs
src/librustc_mir/const_eval/pattern.rs

index 3b9bbc0ba8b44f84bf4e45852b8346761905739a..57feffbaf00526545a77000232d809dece3cd811 100644 (file)
 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;
index 25a9e52236773aa02247f9e716330806b95be08b..32f834daa4c7835f503921f129c8fd08d4023462 100644 (file)
@@ -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 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,
-    }
-}
index 0b8a96332b0f4f19cab6dde65bc84a2eb52cb6f0..27649146eba614b4dd5640c243b0fd5d1aa1ebdd 100644 (file)
 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 @@ fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
         }
     }
 }
+
+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,
+    }
+}