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;
// 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;
use syntax::ast;
-use std::cmp::Ordering;
-
use rustc_const_math::*;
/// * `DefId` is the id of the constant.
-> 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,
- }
-}
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;
}
}
}
+
+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,
+ }
+}