Skip to content

Commit ff3ae32

Browse files
committed
rustc: move Debug impls from ppaux to ty::structural_impls.
1 parent 206b0f2 commit ff3ae32

File tree

3 files changed

+274
-276
lines changed

3 files changed

+274
-276
lines changed

src/librustc/ty/structural_impls.rs

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,273 @@
33
//! hand, though we've recently added some macros (e.g.,
44
//! `BraceStructLiftImpl!`) to help with the tedium.
55
6+
use hir::def::Namespace;
67
use mir::ProjectionKind;
78
use mir::interpret::ConstValue;
89
use ty::{self, Lift, Ty, TyCtxt};
910
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
11+
use ty::print::{FmtPrinter, PrintCx, Printer};
1012
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1113
use smallvec::SmallVec;
1214
use mir::interpret;
1315

16+
use std::fmt;
17+
use std::iter;
1418
use std::rc::Rc;
1519

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

src/librustc/ty/subst.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use syntax_pos::{Span, DUMMY_SP};
1010
use smallvec::SmallVec;
1111

1212
use core::intrinsics;
13+
use std::fmt;
1314
use std::cmp::Ordering;
1415
use std::marker::PhantomData;
1516
use std::mem;
@@ -60,6 +61,15 @@ impl<'tcx> UnpackedKind<'tcx> {
6061
}
6162
}
6263

64+
impl fmt::Debug for Kind<'tcx> {
65+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66+
match self.unpack() {
67+
UnpackedKind::Lifetime(lt) => lt.fmt(f),
68+
UnpackedKind::Type(ty) => ty.fmt(f),
69+
}
70+
}
71+
}
72+
6373
impl<'tcx> Ord for Kind<'tcx> {
6474
fn cmp(&self, other: &Kind<'_>) -> Ordering {
6575
self.unpack().cmp(&other.unpack())

0 commit comments

Comments
 (0)