use middle::ty::TyClosure;
use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
use middle::ty::{self, TypeAndMut, Ty, HasTypeFlags};
-use middle::ty_fold::{self, TypeFoldable};
+use middle::ty::fold::TypeFoldable;
use std::fmt;
use syntax::abi;
use syntax::parse::token;
-use syntax::{ast, ast_util};
+use syntax::ast::DUMMY_NODE_ID;
+use rustc_front::hir as ast;
pub fn verbose() -> bool {
ty::tls::with(|tcx| tcx.sess.verbose())
}
};
- let new_value = ty_fold::replace_late_bound_regions(tcx, &value, |br| {
+ let new_value = tcx.replace_late_bound_regions(&value, |br| {
let _ = start_or_continue(f, "for<", ", ");
ty::ReLateBound(ty::DebruijnIndex::new(1), match br {
ty::BrNamed(_, name) => {
ty::BrEnv => {
let name = token::intern("'r");
let _ = write!(f, "{}", name);
- ty::BrNamed(DefId::local(ast::DUMMY_NODE_ID), name)
+ ty::BrNamed(DefId::local(DUMMY_NODE_ID), name)
}
})
}).0;
struct TraitAndProjections<'tcx>(ty::TraitRef<'tcx>, Vec<ty::ProjectionPredicate<'tcx>>);
impl<'tcx> TypeFoldable<'tcx> for TraitAndProjections<'tcx> {
- fn fold_with<F:ty_fold::TypeFolder<'tcx>>(&self, folder: &mut F)
+ fn fold_with<F:ty::fold::TypeFolder<'tcx>>(&self, folder: &mut F)
-> TraitAndProjections<'tcx> {
TraitAndProjections(self.0.fold_with(folder), self.1.fold_with(folder))
}
impl<'tcx> fmt::Debug for ty::TypeParameterDef<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "TypeParameterDef({:?}, {:?}/{})",
- self.def_id, self.space, self.index)
+ write!(f, "TypeParameterDef({}, {}:{}, {:?}/{})",
+ self.name,
+ self.def_id.krate, self.def_id.node,
+ self.space, self.index)
+ }
+}
+
+impl fmt::Debug for ty::RegionParameterDef {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "RegionParameterDef({}, {}:{}, {:?}/{}, {:?})",
+ self.name,
+ self.def_id.krate, self.def_id.node,
+ self.space, self.index,
+ self.bounds)
}
}
}
}
+impl<'tcx> fmt::Debug for ty::adjustment::AutoAdjustment<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ ty::adjustment::AdjustReifyFnPointer => {
+ write!(f, "AdjustReifyFnPointer")
+ }
+ ty::adjustment::AdjustUnsafeFnPointer => {
+ write!(f, "AdjustUnsafeFnPointer")
+ }
+ ty::adjustment::AdjustDerefRef(ref data) => {
+ write!(f, "{:?}", data)
+ }
+ }
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::adjustment::AutoDerefRef<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "AutoDerefRef({}, unsize={:?}, {:?})",
+ self.autoderefs, self.unsize, self.autoref)
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::TraitTy<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "TraitTy({:?},{:?})",
+ self.principal,
+ self.bounds)
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::Predicate<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ ty::Predicate::Trait(ref a) => write!(f, "{:?}", a),
+ ty::Predicate::Equate(ref pair) => write!(f, "{:?}", pair),
+ ty::Predicate::RegionOutlives(ref pair) => write!(f, "{:?}", pair),
+ ty::Predicate::TypeOutlives(ref pair) => write!(f, "{:?}", pair),
+ ty::Predicate::Projection(ref pair) => write!(f, "{:?}", pair),
+ ty::Predicate::WellFormed(ty) => write!(f, "WF({:?})", ty),
+ ty::Predicate::ObjectSafe(trait_def_id) => {
+ write!(f, "ObjectSafe({:?})", trait_def_id)
+ }
+ }
+ }
+}
+
impl fmt::Display for ty::BoundRegion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if verbose() {
}
}
+impl fmt::Debug for ty::BoundRegion {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ BrAnon(n) => write!(f, "BrAnon({:?})", n),
+ BrFresh(n) => write!(f, "BrFresh({:?})", n),
+ BrNamed(did, name) => {
+ write!(f, "BrNamed({}:{}, {:?})", did.krate, did.node, name)
+ }
+ BrEnv => "BrEnv".fmt(f),
+ }
+ }
+}
+
impl fmt::Debug for ty::Region {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
}
}
+impl<'tcx> fmt::Debug for ty::ClosureTy<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ClosureTy({},{:?},{})",
+ self.unsafety,
+ self.sig,
+ self.abi)
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::ClosureUpvar<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ClosureUpvar({:?},{:?})",
+ self.def,
+ self.ty)
+ }
+}
+
+impl<'a, 'tcx> fmt::Debug for ty::ParameterEnvironment<'a, 'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "ParameterEnvironment(\
+ free_substs={:?}, \
+ implicit_region_bound={:?}, \
+ caller_bounds={:?})",
+ self.free_substs,
+ self.implicit_region_bound,
+ self.caller_bounds)
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::ObjectLifetimeDefault {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ ty::ObjectLifetimeDefault::Ambiguous => write!(f, "Ambiguous"),
+ ty::ObjectLifetimeDefault::BaseDefault => write!(f, "BaseDefault"),
+ ty::ObjectLifetimeDefault::Specific(ref r) => write!(f, "{:?}", r),
+ }
+ }
+}
+
impl fmt::Display for ty::Region {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if verbose() {
}
}
+impl fmt::Debug for ty::Variance {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str(match *self {
+ ty::Covariant => "+",
+ ty::Contravariant => "-",
+ ty::Invariant => "o",
+ ty::Bivariant => "*",
+ })
+ }
+}
+
impl fmt::Debug for ty::ItemVariances {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ItemVariances(types={:?}, regions={:?})",
}
}
+impl fmt::Debug for ty::TyVid {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "_#{}t", self.index)
+ }
+}
+
+impl fmt::Debug for ty::IntVid {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "_#{}i", self.index)
+ }
+}
+
+impl fmt::Debug for ty::FloatVid {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "_#{}f", self.index)
+ }
+}
+
+impl fmt::Debug for ty::RegionVid {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "'_#{}r", self.index)
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "({:?}; variadic: {})->{:?}", self.inputs, self.variadic, self.output)
+ }
+}
+
+impl fmt::Debug for ty::InferTy {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ ty::TyVar(ref v) => v.fmt(f),
+ ty::IntVar(ref v) => v.fmt(f),
+ ty::FloatVar(ref v) => v.fmt(f),
+ ty::FreshTy(v) => write!(f, "FreshTy({:?})", v),
+ ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
+ ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
+ }
+ }
+}
+
+impl fmt::Debug for ty::IntVarValue {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ ty::IntType(ref v) => v.fmt(f),
+ ty::UintType(ref v) => v.fmt(f),
+ }
+ }
+}
+
// The generic impl doesn't work yet because projections are not
// normalized under HRTB.
/*impl<T> fmt::Display for ty::Binder<T>
}
}
+pub fn int_ty_to_string(t: ast::IntTy, val: Option<i64>) -> String {
+ let s = match t {
+ ast::TyIs => "isize",
+ ast::TyI8 => "i8",
+ ast::TyI16 => "i16",
+ ast::TyI32 => "i32",
+ ast::TyI64 => "i64"
+ };
+
+ match val {
+ // cast to a u64 so we can correctly print INT64_MIN. All integral types
+ // are parsed as u64, so we wouldn't want to print an extra negative
+ // sign.
+ Some(n) => format!("{}{}", n as u64, s),
+ None => s.to_string()
+ }
+}
+
+pub fn uint_ty_to_string(t: ast::UintTy, val: Option<u64>) -> String {
+ let s = match t {
+ ast::TyUs => "usize",
+ ast::TyU8 => "u8",
+ ast::TyU16 => "u16",
+ ast::TyU32 => "u32",
+ ast::TyU64 => "u64"
+ };
+
+ match val {
+ Some(n) => format!("{}{}", n, s),
+ None => s.to_string()
+ }
+}
+
+
+pub fn float_ty_to_string(t: ast::FloatTy) -> String {
+ match t {
+ ast::TyF32 => "f32".to_string(),
+ ast::TyF64 => "f64".to_string(),
+ }
+}
+
impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TyBool => write!(f, "bool"),
TyChar => write!(f, "char"),
- TyInt(t) => write!(f, "{}", ast_util::int_ty_to_string(t, None)),
- TyUint(t) => write!(f, "{}", ast_util::uint_ty_to_string(t, None)),
- TyFloat(t) => write!(f, "{}", ast_util::float_ty_to_string(t)),
+ TyInt(t) => write!(f, "{}", int_ty_to_string(t, None)),
+ TyUint(t) => write!(f, "{}", uint_ty_to_string(t, None)),
+ TyFloat(t) => write!(f, "{}", float_ty_to_string(t)),
TyBox(typ) => write!(f, "Box<{}>", typ),
TyRawPtr(ref tm) => {
write!(f, "*{} {}", match tm.mutbl {