|
3 | 3 | //! hand, though we've recently added some macros (e.g.,
|
4 | 4 | //! `BraceStructLiftImpl!`) to help with the tedium.
|
5 | 5 |
|
| 6 | +use crate::hir::def::Namespace; |
6 | 7 | use crate::mir::ProjectionKind;
|
7 | 8 | use crate::mir::interpret::ConstValue;
|
8 | 9 | use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid, InferConst};
|
9 | 10 | use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
| 11 | +use crate::ty::print::{FmtPrinter, PrintCx, Printer}; |
10 | 12 | use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
11 | 13 | use smallvec::SmallVec;
|
12 | 14 | use crate::mir::interpret;
|
13 | 15 |
|
| 16 | +use std::fmt; |
| 17 | +use std::iter; |
14 | 18 | use std::marker::PhantomData;
|
15 | 19 | use std::rc::Rc;
|
16 | 20 |
|
| 21 | +impl fmt::Debug for ty::GenericParamDef { |
| 22 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 23 | + let type_name = match self.kind { |
| 24 | + ty::GenericParamDefKind::Lifetime => "Lifetime", |
| 25 | + ty::GenericParamDefKind::Type {..} => "Type", |
| 26 | + ty::GenericParamDefKind::Const => "Const", |
| 27 | + }; |
| 28 | + write!(f, "{}({}, {:?}, {})", |
| 29 | + type_name, |
| 30 | + self.name, |
| 31 | + self.def_id, |
| 32 | + self.index) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +impl fmt::Debug for ty::TraitDef { |
| 37 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 38 | + PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::TypeNS), |cx| { |
| 39 | + cx.print_def_path(self.def_id, None, iter::empty())?; |
| 40 | + Ok(()) |
| 41 | + }) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl fmt::Debug for ty::AdtDef { |
| 46 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 47 | + PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::TypeNS), |cx| { |
| 48 | + cx.print_def_path(self.did, None, iter::empty())?; |
| 49 | + Ok(()) |
| 50 | + }) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +impl fmt::Debug for ty::ClosureUpvar<'tcx> { |
| 55 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 56 | + write!(f, "ClosureUpvar({:?},{:?})", |
| 57 | + self.def, |
| 58 | + self.ty) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +impl fmt::Debug for ty::UpvarId { |
| 63 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 64 | + let name = ty::tls::with(|tcx| { |
| 65 | + tcx.hir().name_by_hir_id(self.var_path.hir_id) |
| 66 | + }); |
| 67 | + write!(f, "UpvarId({:?};`{}`;{:?})", |
| 68 | + self.var_path.hir_id, |
| 69 | + name, |
| 70 | + self.closure_expr_id) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +impl fmt::Debug for ty::UpvarBorrow<'tcx> { |
| 75 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 76 | + write!(f, "UpvarBorrow({:?}, {:?})", |
| 77 | + self.kind, self.region) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +impl fmt::Debug for ty::ExistentialTraitRef<'tcx> { |
| 82 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 83 | + fmt::Display::fmt(self, f) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +impl fmt::Debug for ty::adjustment::Adjustment<'tcx> { |
| 88 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 89 | + write!(f, "{:?} -> {}", self.kind, self.target) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +impl fmt::Debug for ty::BoundRegion { |
| 94 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 95 | + match *self { |
| 96 | + ty::BrAnon(n) => write!(f, "BrAnon({:?})", n), |
| 97 | + ty::BrFresh(n) => write!(f, "BrFresh({:?})", n), |
| 98 | + ty::BrNamed(did, name) => { |
| 99 | + write!(f, "BrNamed({:?}:{:?}, {})", |
| 100 | + did.krate, did.index, name) |
| 101 | + } |
| 102 | + ty::BrEnv => write!(f, "BrEnv"), |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +impl fmt::Debug for ty::RegionKind { |
| 108 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 109 | + match *self { |
| 110 | + ty::ReEarlyBound(ref data) => { |
| 111 | + write!(f, "ReEarlyBound({}, {})", |
| 112 | + data.index, |
| 113 | + data.name) |
| 114 | + } |
| 115 | + |
| 116 | + ty::ReClosureBound(ref vid) => { |
| 117 | + write!(f, "ReClosureBound({:?})", vid) |
| 118 | + } |
| 119 | + |
| 120 | + ty::ReLateBound(binder_id, ref bound_region) => { |
| 121 | + write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region) |
| 122 | + } |
| 123 | + |
| 124 | + ty::ReFree(ref fr) => fr.fmt(f), |
| 125 | + |
| 126 | + ty::ReScope(id) => write!(f, "ReScope({:?})", id), |
| 127 | + |
| 128 | + ty::ReStatic => write!(f, "ReStatic"), |
| 129 | + |
| 130 | + ty::ReVar(ref vid) => vid.fmt(f), |
| 131 | + |
| 132 | + ty::RePlaceholder(placeholder) => { |
| 133 | + write!(f, "RePlaceholder({:?})", placeholder) |
| 134 | + } |
| 135 | + |
| 136 | + ty::ReEmpty => write!(f, "ReEmpty"), |
| 137 | + |
| 138 | + ty::ReErased => write!(f, "ReErased"), |
| 139 | + } |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +impl fmt::Debug for ty::FreeRegion { |
| 144 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 145 | + write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region) |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +impl fmt::Debug for ty::Variance { |
| 150 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 151 | + f.write_str(match *self { |
| 152 | + ty::Covariant => "+", |
| 153 | + ty::Contravariant => "-", |
| 154 | + ty::Invariant => "o", |
| 155 | + ty::Bivariant => "*", |
| 156 | + }) |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +impl fmt::Debug for ty::FnSig<'tcx> { |
| 161 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 162 | + write!(f, "({:?}; c_variadic: {})->{:?}", |
| 163 | + self.inputs(), self.c_variadic, self.output()) |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +impl fmt::Debug for ty::TyVid { |
| 168 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 169 | + write!(f, "_#{}t", self.index) |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 173 | +impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> { |
| 174 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 175 | + write!(f, "_#{}c", self.index) |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +impl fmt::Debug for ty::IntVid { |
| 180 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 181 | + write!(f, "_#{}i", self.index) |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +impl fmt::Debug for ty::FloatVid { |
| 186 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 187 | + write!(f, "_#{}f", self.index) |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +impl fmt::Debug for ty::RegionVid { |
| 192 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 193 | + write!(f, "'_#{}r", self.index()) |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +impl fmt::Debug for ty::InferTy { |
| 198 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 199 | + match *self { |
| 200 | + ty::TyVar(ref v) => v.fmt(f), |
| 201 | + ty::IntVar(ref v) => v.fmt(f), |
| 202 | + ty::FloatVar(ref v) => v.fmt(f), |
| 203 | + ty::FreshTy(v) => write!(f, "FreshTy({:?})", v), |
| 204 | + ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v), |
| 205 | + ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v), |
| 206 | + } |
| 207 | + } |
| 208 | +} |
| 209 | + |
| 210 | +impl fmt::Debug for ty::IntVarValue { |
| 211 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 212 | + match *self { |
| 213 | + ty::IntType(ref v) => v.fmt(f), |
| 214 | + ty::UintType(ref v) => v.fmt(f), |
| 215 | + } |
| 216 | + } |
| 217 | +} |
| 218 | + |
| 219 | +impl fmt::Debug for ty::FloatVarValue { |
| 220 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 221 | + self.0.fmt(f) |
| 222 | + } |
| 223 | +} |
| 224 | + |
| 225 | +impl fmt::Debug for ty::TraitRef<'tcx> { |
| 226 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 227 | + // HACK(eddyb) this is used across the compiler to print |
| 228 | + // a `TraitRef` qualified (with the Self type explicit), |
| 229 | + // instead of having a different way to make that choice. |
| 230 | + write!(f, "<{} as {}>", self.self_ty(), self) |
| 231 | + } |
| 232 | +} |
| 233 | + |
| 234 | +impl fmt::Debug for Ty<'tcx> { |
| 235 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 236 | + fmt::Display::fmt(self, f) |
| 237 | + } |
| 238 | +} |
| 239 | + |
| 240 | +impl fmt::Debug for ty::ParamTy { |
| 241 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 242 | + write!(f, "{}/#{}", self.name, self.idx) |
| 243 | + } |
| 244 | +} |
| 245 | + |
| 246 | +impl fmt::Debug for ty::ParamConst { |
| 247 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 248 | + write!(f, "{}/#{}", self.name, self.index) |
| 249 | + } |
| 250 | +} |
| 251 | + |
| 252 | +impl fmt::Debug for ty::TraitPredicate<'tcx> { |
| 253 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 254 | + write!(f, "TraitPredicate({:?})", self.trait_ref) |
| 255 | + } |
| 256 | +} |
| 257 | + |
| 258 | +impl fmt::Debug for ty::ProjectionPredicate<'tcx> { |
| 259 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 260 | + write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_ty, self.ty) |
| 261 | + } |
| 262 | +} |
| 263 | + |
| 264 | +impl fmt::Debug for ty::Predicate<'tcx> { |
| 265 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 266 | + match *self { |
| 267 | + ty::Predicate::Trait(ref a) => a.fmt(f), |
| 268 | + ty::Predicate::Subtype(ref pair) => pair.fmt(f), |
| 269 | + ty::Predicate::RegionOutlives(ref pair) => pair.fmt(f), |
| 270 | + ty::Predicate::TypeOutlives(ref pair) => pair.fmt(f), |
| 271 | + ty::Predicate::Projection(ref pair) => pair.fmt(f), |
| 272 | + ty::Predicate::WellFormed(ty) => write!(f, "WellFormed({:?})", ty), |
| 273 | + ty::Predicate::ObjectSafe(trait_def_id) => { |
| 274 | + write!(f, "ObjectSafe({:?})", trait_def_id) |
| 275 | + } |
| 276 | + ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { |
| 277 | + write!(f, "ClosureKind({:?}, {:?}, {:?})", |
| 278 | + closure_def_id, closure_substs, kind) |
| 279 | + } |
| 280 | + ty::Predicate::ConstEvaluatable(def_id, substs) => { |
| 281 | + write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | +} |
| 286 | + |
17 | 287 | ///////////////////////////////////////////////////////////////////////////
|
18 | 288 | // Atomic structs
|
19 | 289 | //
|
|
0 commit comments