]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | //! Debug impls for types. |
2 | ||
5e7ed085 | 3 | use std::fmt::{self, Debug, Display, Error, Formatter}; |
f9f354fc XL |
4 | |
5 | use super::*; | |
6 | ||
5e7ed085 FG |
7 | /// Wrapper to allow forwarding to `Display::fmt`, `Debug::fmt`, etc. |
8 | pub struct Fmt<F>(pub F) | |
9 | where | |
10 | F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result; | |
11 | ||
12 | impl<F> fmt::Display for Fmt<F> | |
13 | where | |
14 | F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result, | |
15 | { | |
16 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
17 | (self.0)(f) | |
18 | } | |
19 | } | |
20 | ||
f9f354fc XL |
21 | impl<I: Interner> Debug for TraitId<I> { |
22 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
23 | I::debug_trait_id(*self, fmt).unwrap_or_else(|| write!(fmt, "TraitId({:?})", self.0)) | |
24 | } | |
25 | } | |
26 | ||
f035d41b | 27 | impl<I: Interner> Debug for AdtId<I> { |
f9f354fc | 28 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
f035d41b | 29 | I::debug_adt_id(*self, fmt).unwrap_or_else(|| write!(fmt, "AdtId({:?})", self.0)) |
f9f354fc XL |
30 | } |
31 | } | |
32 | ||
33 | impl<I: Interner> Debug for AssocTypeId<I> { | |
34 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
35 | I::debug_assoc_type_id(*self, fmt) | |
36 | .unwrap_or_else(|| write!(fmt, "AssocTypeId({:?})", self.0)) | |
37 | } | |
38 | } | |
39 | ||
f035d41b XL |
40 | impl<I: Interner> Debug for FnDefId<I> { |
41 | fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result { | |
42 | I::debug_fn_def_id(*self, fmt).unwrap_or_else(|| write!(fmt, "FnDefId({:?})", self.0)) | |
43 | } | |
44 | } | |
45 | ||
46 | impl<I: Interner> Debug for ClosureId<I> { | |
47 | fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result { | |
48 | I::debug_closure_id(*self, fmt).unwrap_or_else(|| write!(fmt, "ClosureId({:?})", self.0)) | |
49 | } | |
50 | } | |
51 | ||
29967ef6 XL |
52 | impl<I: Interner> Debug for GeneratorId<I> { |
53 | fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result { | |
54 | I::debug_generator_id(*self, fmt) | |
55 | .unwrap_or_else(|| write!(fmt, "GeneratorId({:?})", self.0)) | |
56 | } | |
57 | } | |
58 | ||
1b1a35ee XL |
59 | impl<I: Interner> Debug for ForeignDefId<I> { |
60 | fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result { | |
61 | I::debug_foreign_def_id(*self, fmt) | |
62 | .unwrap_or_else(|| write!(fmt, "ForeignDefId({:?})", self.0)) | |
63 | } | |
64 | } | |
65 | ||
f9f354fc XL |
66 | impl<I: Interner> Debug for Ty<I> { |
67 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
68 | I::debug_ty(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
69 | } | |
70 | } | |
71 | ||
72 | impl<I: Interner> Debug for Lifetime<I> { | |
73 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
74 | I::debug_lifetime(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
75 | } | |
76 | } | |
77 | ||
f035d41b XL |
78 | impl<I: Interner> Debug for Const<I> { |
79 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
80 | I::debug_const(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
81 | } | |
82 | } | |
83 | ||
84 | impl<I: Interner> Debug for ConcreteConst<I> { | |
85 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
86 | write!(fmt, "{:?}", self.interned) | |
87 | } | |
88 | } | |
89 | ||
90 | impl<I: Interner> Debug for GenericArg<I> { | |
f9f354fc | 91 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
f035d41b | 92 | I::debug_generic_arg(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) |
f9f354fc XL |
93 | } |
94 | } | |
95 | ||
96 | impl<I: Interner> Debug for Goal<I> { | |
97 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
98 | I::debug_goal(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
99 | } | |
100 | } | |
101 | ||
102 | impl<I: Interner> Debug for Goals<I> { | |
103 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
104 | I::debug_goals(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
105 | } | |
106 | } | |
107 | ||
108 | impl<I: Interner> Debug for ProgramClauseImplication<I> { | |
109 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
110 | I::debug_program_clause_implication(self, fmt) | |
111 | .unwrap_or_else(|| write!(fmt, "ProgramClauseImplication(?)")) | |
112 | } | |
113 | } | |
114 | ||
115 | impl<I: Interner> Debug for ProgramClause<I> { | |
116 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
117 | I::debug_program_clause(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
118 | } | |
119 | } | |
120 | ||
121 | impl<I: Interner> Debug for ProgramClauses<I> { | |
122 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
123 | I::debug_program_clauses(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
124 | } | |
125 | } | |
126 | ||
3dfed10e XL |
127 | impl<I: Interner> Debug for Constraints<I> { |
128 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
129 | I::debug_constraints(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
130 | } | |
131 | } | |
132 | ||
f9f354fc XL |
133 | impl<I: Interner> Debug for SeparatorTraitRef<'_, I> { |
134 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
135 | I::debug_separator_trait_ref(self, fmt) | |
136 | .unwrap_or_else(|| write!(fmt, "SeparatorTraitRef(?)")) | |
137 | } | |
138 | } | |
139 | ||
140 | impl<I: Interner> Debug for AliasTy<I> { | |
141 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
142 | I::debug_alias(self, fmt).unwrap_or_else(|| write!(fmt, "AliasTy(?)")) | |
143 | } | |
144 | } | |
145 | ||
146 | impl<I: Interner> Debug for QuantifiedWhereClauses<I> { | |
147 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
148 | I::debug_quantified_where_clauses(self, fmt) | |
149 | .unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
150 | } | |
151 | } | |
152 | ||
153 | impl<I: Interner> Debug for ProjectionTy<I> { | |
154 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
155 | I::debug_projection_ty(self, fmt).unwrap_or_else(|| { | |
156 | unimplemented!("cannot format ProjectionTy without setting Program in tls") | |
157 | }) | |
158 | } | |
159 | } | |
160 | ||
161 | impl<I: Interner> Debug for OpaqueTy<I> { | |
162 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
163 | I::debug_opaque_ty(self, fmt).unwrap_or_else(|| { | |
164 | unimplemented!("cannot format OpaqueTy without setting Program in tls") | |
165 | }) | |
166 | } | |
167 | } | |
168 | ||
169 | impl<I: Interner> Display for Substitution<I> { | |
170 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
171 | I::debug_substitution(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
172 | } | |
173 | } | |
174 | ||
175 | impl<I: Interner> Debug for OpaqueTyId<I> { | |
176 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
177 | I::debug_opaque_ty_id(*self, fmt).unwrap_or_else(|| write!(fmt, "OpaqueTyId({:?})", self.0)) | |
178 | } | |
179 | } | |
180 | ||
181 | impl Display for UniverseIndex { | |
182 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
183 | write!(fmt, "U{}", self.counter) | |
184 | } | |
185 | } | |
186 | ||
187 | impl Debug for UniverseIndex { | |
188 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
189 | write!(fmt, "U{}", self.counter) | |
190 | } | |
191 | } | |
192 | ||
29967ef6 | 193 | impl<I: Interner> Debug for TyData<I> { |
f9f354fc | 194 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
29967ef6 | 195 | self.kind.fmt(fmt) |
f9f354fc XL |
196 | } |
197 | } | |
198 | ||
29967ef6 | 199 | impl<I: Interner> Debug for TyKind<I> { |
f9f354fc XL |
200 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
201 | match self { | |
29967ef6 XL |
202 | TyKind::BoundVar(db) => write!(fmt, "{:?}", db), |
203 | TyKind::Dyn(clauses) => write!(fmt, "{:?}", clauses), | |
204 | TyKind::InferenceVar(var, TyVariableKind::General) => write!(fmt, "{:?}", var), | |
205 | TyKind::InferenceVar(var, TyVariableKind::Integer) => write!(fmt, "{:?}i", var), | |
206 | TyKind::InferenceVar(var, TyVariableKind::Float) => write!(fmt, "{:?}f", var), | |
207 | TyKind::Alias(alias) => write!(fmt, "{:?}", alias), | |
208 | TyKind::Placeholder(index) => write!(fmt, "{:?}", index), | |
209 | TyKind::Function(function) => write!(fmt, "{:?}", function), | |
210 | TyKind::Adt(id, substitution) => write!(fmt, "{:?}<{:?}>", id, substitution), | |
211 | TyKind::AssociatedType(assoc_ty, substitution) => { | |
212 | write!(fmt, "{:?}<{:?}>", assoc_ty, substitution) | |
213 | } | |
214 | TyKind::Scalar(scalar) => write!(fmt, "{:?}", scalar), | |
215 | TyKind::Str => write!(fmt, "Str"), | |
216 | TyKind::Tuple(arity, substitution) => write!(fmt, "{:?}<{:?}>", arity, substitution), | |
217 | TyKind::OpaqueType(opaque_ty, substitution) => { | |
218 | write!(fmt, "!{:?}<{:?}>", opaque_ty, substitution) | |
219 | } | |
220 | TyKind::Slice(substitution) => write!(fmt, "{{slice}}<{:?}>", substitution), | |
221 | TyKind::FnDef(fn_def, substitution) => write!(fmt, "{:?}<{:?}>", fn_def, substitution), | |
222 | TyKind::Ref(mutability, lifetime, ty) => match mutability { | |
223 | Mutability::Mut => write!(fmt, "(&{:?} mut {:?})", lifetime, ty), | |
224 | Mutability::Not => write!(fmt, "(&{:?} {:?})", lifetime, ty), | |
225 | }, | |
226 | TyKind::Raw(mutability, ty) => match mutability { | |
227 | Mutability::Mut => write!(fmt, "(*mut {:?})", ty), | |
228 | Mutability::Not => write!(fmt, "(*const {:?})", ty), | |
229 | }, | |
230 | TyKind::Never => write!(fmt, "Never"), | |
231 | TyKind::Array(ty, const_) => write!(fmt, "[{:?}; {:?}]", ty, const_), | |
232 | TyKind::Closure(id, substitution) => { | |
233 | write!(fmt, "{{closure:{:?}}}<{:?}>", id, substitution) | |
234 | } | |
235 | TyKind::Generator(generator, substitution) => { | |
236 | write!(fmt, "{:?}<{:?}>", generator, substitution) | |
237 | } | |
238 | TyKind::GeneratorWitness(witness, substitution) => { | |
239 | write!(fmt, "{:?}<{:?}>", witness, substitution) | |
240 | } | |
241 | TyKind::Foreign(foreign_ty) => write!(fmt, "{:?}", foreign_ty), | |
242 | TyKind::Error => write!(fmt, "{{error}}"), | |
f9f354fc XL |
243 | } |
244 | } | |
245 | } | |
246 | ||
247 | impl Debug for BoundVar { | |
248 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
249 | let BoundVar { debruijn, index } = self; | |
250 | write!(fmt, "{:?}.{:?}", debruijn, index) | |
251 | } | |
252 | } | |
253 | ||
254 | impl Debug for DebruijnIndex { | |
255 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
256 | let DebruijnIndex { depth } = self; | |
257 | write!(fmt, "^{}", depth) | |
258 | } | |
259 | } | |
260 | ||
261 | impl<I: Interner> Debug for DynTy<I> { | |
262 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
f035d41b XL |
263 | let DynTy { bounds, lifetime } = self; |
264 | write!(fmt, "dyn {:?} + {:?}", bounds, lifetime) | |
f9f354fc XL |
265 | } |
266 | } | |
267 | ||
268 | impl Debug for InferenceVar { | |
269 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
270 | write!(fmt, "?{}", self.index) | |
271 | } | |
272 | } | |
273 | ||
5869c6ff XL |
274 | impl<I: Interner> Debug for FnSubst<I> { |
275 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
276 | write!(fmt, "{:?}", self.0) | |
277 | } | |
278 | } | |
279 | ||
3dfed10e | 280 | impl<I: Interner> Debug for FnPointer<I> { |
f9f354fc XL |
281 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
282 | // FIXME -- we should introduce some names or something here | |
3dfed10e | 283 | let FnPointer { |
f9f354fc XL |
284 | num_binders, |
285 | substitution, | |
1b1a35ee | 286 | sig, |
f9f354fc | 287 | } = self; |
3dfed10e XL |
288 | write!( |
289 | fmt, | |
5869c6ff XL |
290 | "{}{:?} for<{}> {:?}", |
291 | match sig.safety { | |
292 | Safety::Unsafe => "unsafe ", | |
293 | Safety::Safe => "", | |
294 | }, | |
295 | sig.abi, | |
296 | num_binders, | |
297 | substitution | |
3dfed10e | 298 | ) |
f9f354fc XL |
299 | } |
300 | } | |
301 | ||
302 | impl<I: Interner> Debug for LifetimeData<I> { | |
303 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
304 | match self { | |
305 | LifetimeData::BoundVar(db) => write!(fmt, "'{:?}", db), | |
306 | LifetimeData::InferenceVar(var) => write!(fmt, "'{:?}", var), | |
307 | LifetimeData::Placeholder(index) => write!(fmt, "'{:?}", index), | |
29967ef6 | 308 | LifetimeData::Static => write!(fmt, "'static"), |
5869c6ff XL |
309 | LifetimeData::Empty(UniverseIndex::ROOT) => write!(fmt, "'<empty>"), |
310 | LifetimeData::Empty(universe) => write!(fmt, "'<empty:{:?}>", universe), | |
311 | LifetimeData::Erased => write!(fmt, "'<erased>"), | |
f9f354fc XL |
312 | LifetimeData::Phantom(..) => unreachable!(), |
313 | } | |
314 | } | |
315 | } | |
316 | ||
f035d41b XL |
317 | impl<I: Interner> VariableKinds<I> { |
318 | fn debug(&self) -> VariableKindsDebug<'_, I> { | |
319 | VariableKindsDebug(self) | |
f9f354fc XL |
320 | } |
321 | ||
f035d41b | 322 | /// Helper method for debugging variable kinds. |
5e7ed085 | 323 | pub fn inner_debug(&self, interner: I) -> VariableKindsInnerDebug<'_, I> { |
f035d41b XL |
324 | VariableKindsInnerDebug { |
325 | variable_kinds: self, | |
f9f354fc XL |
326 | interner, |
327 | } | |
328 | } | |
329 | } | |
330 | ||
f035d41b | 331 | struct VariableKindsDebug<'a, I: Interner>(&'a VariableKinds<I>); |
f9f354fc | 332 | |
f035d41b | 333 | impl<'a, I: Interner> Debug for VariableKindsDebug<'a, I> { |
f9f354fc | 334 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
f035d41b | 335 | I::debug_variable_kinds_with_angles(self.0, fmt) |
f9f354fc XL |
336 | .unwrap_or_else(|| write!(fmt, "{:?}", self.0.interned)) |
337 | } | |
338 | } | |
339 | ||
f035d41b XL |
340 | /// Helper struct for showing debug output for `VariableKinds`. |
341 | pub struct VariableKindsInnerDebug<'a, I: Interner> { | |
342 | variable_kinds: &'a VariableKinds<I>, | |
a2a8927a | 343 | interner: I, |
f9f354fc XL |
344 | } |
345 | ||
f035d41b | 346 | impl<'a, I: Interner> Debug for VariableKindsInnerDebug<'a, I> { |
f9f354fc | 347 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
f035d41b XL |
348 | // NB: We print variable kinds as a list delimited by `<>`, |
349 | // like `<K1, K2, ..>`. This is because variable kind lists | |
f9f354fc XL |
350 | // are always associated with binders like `forall<type> { |
351 | // ... }`. | |
352 | write!(fmt, "<")?; | |
f035d41b | 353 | for (index, binder) in self.variable_kinds.iter(self.interner).enumerate() { |
f9f354fc XL |
354 | if index > 0 { |
355 | write!(fmt, ", ")?; | |
356 | } | |
f035d41b | 357 | match binder { |
29967ef6 XL |
358 | VariableKind::Ty(TyVariableKind::General) => write!(fmt, "type")?, |
359 | VariableKind::Ty(TyVariableKind::Integer) => write!(fmt, "integer type")?, | |
360 | VariableKind::Ty(TyVariableKind::Float) => write!(fmt, "float type")?, | |
f035d41b XL |
361 | VariableKind::Lifetime => write!(fmt, "lifetime")?, |
362 | VariableKind::Const(ty) => write!(fmt, "const: {:?}", ty)?, | |
f9f354fc XL |
363 | } |
364 | } | |
365 | write!(fmt, ">") | |
366 | } | |
367 | } | |
368 | ||
f035d41b XL |
369 | impl<I: Interner> Debug for ConstData<I> { |
370 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
371 | match &self.value { | |
372 | ConstValue::BoundVar(db) => write!(fmt, "{:?}", db), | |
373 | ConstValue::InferenceVar(var) => write!(fmt, "{:?}", var), | |
374 | ConstValue::Placeholder(index) => write!(fmt, "{:?}", index), | |
375 | ConstValue::Concrete(evaluated) => write!(fmt, "{:?}", evaluated), | |
376 | } | |
377 | } | |
378 | } | |
379 | ||
f9f354fc XL |
380 | impl<I: Interner> Debug for GoalData<I> { |
381 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
382 | match self { | |
383 | GoalData::Quantified(qkind, ref subgoal) => write!( | |
384 | fmt, | |
385 | "{:?}{:?} {{ {:?} }}", | |
386 | qkind, | |
387 | subgoal.binders.debug(), | |
388 | subgoal.value | |
389 | ), | |
390 | GoalData::Implies(ref wc, ref g) => write!(fmt, "if ({:?}) {{ {:?} }}", wc, g), | |
391 | GoalData::All(ref goals) => write!(fmt, "all{:?}", goals), | |
392 | GoalData::Not(ref g) => write!(fmt, "not {{ {:?} }}", g), | |
393 | GoalData::EqGoal(ref wc) => write!(fmt, "{:?}", wc), | |
5869c6ff | 394 | GoalData::SubtypeGoal(ref wc) => write!(fmt, "{:?}", wc), |
f9f354fc | 395 | GoalData::DomainGoal(ref wc) => write!(fmt, "{:?}", wc), |
3dfed10e | 396 | GoalData::CannotProve => write!(fmt, r"¯\_(ツ)_/¯"), |
f9f354fc XL |
397 | } |
398 | } | |
399 | } | |
400 | ||
f035d41b | 401 | /// Helper struct for showing debug output for `Goals`. |
f9f354fc XL |
402 | pub struct GoalsDebug<'a, I: Interner> { |
403 | goals: &'a Goals<I>, | |
a2a8927a | 404 | interner: I, |
f9f354fc XL |
405 | } |
406 | ||
407 | impl<'a, I: Interner> Debug for GoalsDebug<'a, I> { | |
408 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
409 | write!(fmt, "(")?; | |
410 | for (goal, index) in self.goals.iter(self.interner).zip(0..) { | |
411 | if index > 0 { | |
412 | write!(fmt, ", ")?; | |
413 | } | |
414 | write!(fmt, "{:?}", goal)?; | |
415 | } | |
416 | write!(fmt, ")")?; | |
417 | Ok(()) | |
418 | } | |
419 | } | |
420 | ||
421 | impl<I: Interner> Goals<I> { | |
f035d41b | 422 | /// Show debug output for `Goals`. |
5e7ed085 | 423 | pub fn debug(&self, interner: I) -> GoalsDebug<'_, I> { |
f9f354fc XL |
424 | GoalsDebug { |
425 | goals: self, | |
426 | interner, | |
427 | } | |
428 | } | |
429 | } | |
430 | ||
f035d41b XL |
431 | /// Helper struct for showing debug output for `GenericArgData`. |
432 | pub struct GenericArgDataInnerDebug<'a, I: Interner>(&'a GenericArgData<I>); | |
f9f354fc | 433 | |
f035d41b | 434 | impl<'a, I: Interner> Debug for GenericArgDataInnerDebug<'a, I> { |
f9f354fc XL |
435 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
436 | match self.0 { | |
f035d41b XL |
437 | GenericArgData::Ty(n) => write!(fmt, "{:?}", n), |
438 | GenericArgData::Lifetime(n) => write!(fmt, "{:?}", n), | |
439 | GenericArgData::Const(n) => write!(fmt, "{:?}", n), | |
f9f354fc XL |
440 | } |
441 | } | |
442 | } | |
443 | ||
f035d41b XL |
444 | impl<I: Interner> GenericArgData<I> { |
445 | /// Helper method for debugging `GenericArgData`. | |
446 | pub fn inner_debug(&self) -> GenericArgDataInnerDebug<'_, I> { | |
447 | GenericArgDataInnerDebug(self) | |
f9f354fc XL |
448 | } |
449 | } | |
450 | ||
f035d41b | 451 | /// Helper struct for showing debug output for program clause implications. |
f9f354fc XL |
452 | pub struct ProgramClauseImplicationDebug<'a, I: Interner> { |
453 | pci: &'a ProgramClauseImplication<I>, | |
a2a8927a | 454 | interner: I, |
f9f354fc XL |
455 | } |
456 | ||
457 | impl<'a, I: Interner> Debug for ProgramClauseImplicationDebug<'a, I> { | |
458 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
459 | let ProgramClauseImplicationDebug { pci, interner } = self; | |
460 | write!(fmt, "{:?}", pci.consequence)?; | |
461 | ||
a2a8927a | 462 | let conditions = pci.conditions.as_slice(*interner); |
f9f354fc XL |
463 | |
464 | let conds = conditions.len(); | |
465 | if conds == 0 { | |
466 | return Ok(()); | |
467 | } | |
468 | ||
469 | write!(fmt, " :- ")?; | |
470 | for cond in &conditions[..conds - 1] { | |
471 | write!(fmt, "{:?}, ", cond)?; | |
472 | } | |
473 | write!(fmt, "{:?}", conditions[conds - 1]) | |
474 | } | |
475 | } | |
476 | ||
477 | impl<I: Interner> ProgramClauseImplication<I> { | |
f035d41b | 478 | /// Show debug output for the program clause implication. |
5e7ed085 | 479 | pub fn debug(&self, interner: I) -> ProgramClauseImplicationDebug<'_, I> { |
f9f354fc XL |
480 | ProgramClauseImplicationDebug { |
481 | pci: self, | |
482 | interner, | |
483 | } | |
484 | } | |
485 | } | |
486 | ||
f035d41b | 487 | /// Helper struct for showing debug output for application types. |
29967ef6 XL |
488 | pub struct TyKindDebug<'a, I: Interner> { |
489 | ty: &'a TyKind<I>, | |
a2a8927a | 490 | interner: I, |
f9f354fc XL |
491 | } |
492 | ||
29967ef6 | 493 | impl<'a, I: Interner> Debug for TyKindDebug<'a, I> { |
f9f354fc | 494 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
29967ef6 XL |
495 | let interner = self.interner; |
496 | match self.ty { | |
497 | TyKind::BoundVar(db) => write!(fmt, "{:?}", db), | |
498 | TyKind::Dyn(clauses) => write!(fmt, "{:?}", clauses), | |
499 | TyKind::InferenceVar(var, TyVariableKind::General) => write!(fmt, "{:?}", var), | |
500 | TyKind::InferenceVar(var, TyVariableKind::Integer) => write!(fmt, "{:?}i", var), | |
501 | TyKind::InferenceVar(var, TyVariableKind::Float) => write!(fmt, "{:?}f", var), | |
502 | TyKind::Alias(alias) => write!(fmt, "{:?}", alias), | |
503 | TyKind::Placeholder(index) => write!(fmt, "{:?}", index), | |
504 | TyKind::Function(function) => write!(fmt, "{:?}", function), | |
505 | TyKind::Adt(id, substitution) => { | |
506 | write!(fmt, "{:?}{:?}", id, substitution.with_angle(interner)) | |
507 | } | |
508 | TyKind::AssociatedType(assoc_ty, substitution) => { | |
509 | write!(fmt, "{:?}{:?}", assoc_ty, substitution.with_angle(interner)) | |
510 | } | |
511 | TyKind::Scalar(scalar) => write!(fmt, "{:?}", scalar), | |
512 | TyKind::Str => write!(fmt, "Str"), | |
513 | TyKind::Tuple(arity, substitution) => { | |
514 | write!(fmt, "{:?}{:?}", arity, substitution.with_angle(interner)) | |
515 | } | |
516 | TyKind::OpaqueType(opaque_ty, substitution) => write!( | |
517 | fmt, | |
518 | "!{:?}{:?}", | |
519 | opaque_ty, | |
520 | substitution.with_angle(interner) | |
521 | ), | |
522 | TyKind::Slice(ty) => write!(fmt, "[{:?}]", ty), | |
523 | TyKind::FnDef(fn_def, substitution) => { | |
524 | write!(fmt, "{:?}{:?}", fn_def, substitution.with_angle(interner)) | |
525 | } | |
526 | TyKind::Ref(mutability, lifetime, ty) => match mutability { | |
527 | Mutability::Mut => write!(fmt, "(&{:?} mut {:?})", lifetime, ty), | |
528 | Mutability::Not => write!(fmt, "(&{:?} {:?})", lifetime, ty), | |
529 | }, | |
530 | TyKind::Raw(mutability, ty) => match mutability { | |
531 | Mutability::Mut => write!(fmt, "(*mut {:?})", ty), | |
532 | Mutability::Not => write!(fmt, "(*const {:?})", ty), | |
533 | }, | |
534 | TyKind::Never => write!(fmt, "Never"), | |
535 | TyKind::Array(ty, const_) => write!(fmt, "[{:?}; {:?}]", ty, const_), | |
536 | TyKind::Closure(id, substitution) => write!( | |
537 | fmt, | |
538 | "{{closure:{:?}}}{:?}", | |
539 | id, | |
540 | substitution.with_angle(interner) | |
541 | ), | |
542 | TyKind::Generator(generator, substitution) => write!( | |
543 | fmt, | |
544 | "{:?}{:?}", | |
545 | generator, | |
546 | substitution.with_angle(interner) | |
547 | ), | |
548 | TyKind::GeneratorWitness(witness, substitution) => { | |
549 | write!(fmt, "{:?}{:?}", witness, substitution.with_angle(interner)) | |
550 | } | |
551 | TyKind::Foreign(foreign_ty) => write!(fmt, "{:?}", foreign_ty,), | |
552 | TyKind::Error => write!(fmt, "{{error}}"), | |
553 | } | |
f9f354fc XL |
554 | } |
555 | } | |
556 | ||
29967ef6 | 557 | impl<I: Interner> TyKind<I> { |
f035d41b | 558 | /// Show debug output for the application type. |
5e7ed085 | 559 | pub fn debug(&self, interner: I) -> TyKindDebug<'_, I> { |
29967ef6 | 560 | TyKindDebug { ty: self, interner } |
f9f354fc XL |
561 | } |
562 | } | |
563 | ||
f035d41b | 564 | /// Helper struct for showing debug output for substitutions. |
f9f354fc XL |
565 | pub struct SubstitutionDebug<'a, I: Interner> { |
566 | substitution: &'a Substitution<I>, | |
a2a8927a | 567 | interner: I, |
f9f354fc XL |
568 | } |
569 | ||
570 | impl<'a, I: Interner> Debug for SubstitutionDebug<'a, I> { | |
571 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
572 | let SubstitutionDebug { | |
573 | substitution, | |
574 | interner, | |
575 | } = self; | |
576 | let mut first = true; | |
577 | ||
578 | write!(fmt, "[")?; | |
579 | ||
a2a8927a | 580 | for (index, value) in substitution.iter(*interner).enumerate() { |
f9f354fc XL |
581 | if first { |
582 | first = false; | |
583 | } else { | |
584 | write!(fmt, ", ")?; | |
585 | } | |
586 | ||
587 | write!(fmt, "?{} := {:?}", index, value)?; | |
588 | } | |
589 | ||
590 | write!(fmt, "]")?; | |
591 | ||
592 | Ok(()) | |
593 | } | |
594 | } | |
595 | ||
596 | impl<I: Interner> Substitution<I> { | |
f035d41b | 597 | /// Show debug output for the substitution. |
5e7ed085 | 598 | pub fn debug(&self, interner: I) -> SubstitutionDebug<'_, I> { |
f9f354fc XL |
599 | SubstitutionDebug { |
600 | substitution: self, | |
601 | interner, | |
602 | } | |
603 | } | |
604 | } | |
605 | ||
606 | impl Debug for PlaceholderIndex { | |
607 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
608 | let PlaceholderIndex { ui, idx } = self; | |
609 | write!(fmt, "!{}_{}", ui.counter, idx) | |
610 | } | |
611 | } | |
612 | ||
613 | impl<I: Interner> TraitRef<I> { | |
f035d41b | 614 | /// Returns a "Debuggable" type that prints like `P0 as Trait<P1..>`. |
f9f354fc XL |
615 | pub fn with_as(&self) -> impl std::fmt::Debug + '_ { |
616 | SeparatorTraitRef { | |
617 | trait_ref: self, | |
618 | separator: " as ", | |
619 | } | |
620 | } | |
621 | ||
f035d41b | 622 | /// Returns a "Debuggable" type that prints like `P0: Trait<P1..>`. |
f9f354fc XL |
623 | pub fn with_colon(&self) -> impl std::fmt::Debug + '_ { |
624 | SeparatorTraitRef { | |
625 | trait_ref: self, | |
626 | separator: ": ", | |
627 | } | |
628 | } | |
629 | } | |
630 | ||
631 | impl<I: Interner> Debug for TraitRef<I> { | |
632 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
633 | Debug::fmt(&self.with_as(), fmt) | |
634 | } | |
635 | } | |
636 | ||
f035d41b | 637 | /// Trait ref with associated separator used for debug output. |
f9f354fc | 638 | pub struct SeparatorTraitRef<'me, I: Interner> { |
f035d41b | 639 | /// The `TraitRef` itself. |
f9f354fc | 640 | pub trait_ref: &'me TraitRef<I>, |
f035d41b XL |
641 | |
642 | /// The separator used for displaying the `TraitRef`. | |
f9f354fc XL |
643 | pub separator: &'me str, |
644 | } | |
645 | ||
f035d41b | 646 | /// Helper struct for showing debug output for the `SeperatorTraitRef`. |
f9f354fc XL |
647 | pub struct SeparatorTraitRefDebug<'a, 'me, I: Interner> { |
648 | separator_trait_ref: &'a SeparatorTraitRef<'me, I>, | |
a2a8927a | 649 | interner: I, |
f9f354fc XL |
650 | } |
651 | ||
652 | impl<'a, 'me, I: Interner> Debug for SeparatorTraitRefDebug<'a, 'me, I> { | |
653 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
654 | let SeparatorTraitRefDebug { | |
655 | separator_trait_ref, | |
656 | interner, | |
657 | } = self; | |
658 | let parameters = separator_trait_ref | |
659 | .trait_ref | |
660 | .substitution | |
a2a8927a | 661 | .as_slice(*interner); |
f9f354fc XL |
662 | write!( |
663 | fmt, | |
664 | "{:?}{}{:?}{:?}", | |
665 | parameters[0], | |
666 | separator_trait_ref.separator, | |
667 | separator_trait_ref.trait_ref.trait_id, | |
668 | Angle(¶meters[1..]) | |
669 | ) | |
670 | } | |
671 | } | |
672 | ||
673 | impl<'me, I: Interner> SeparatorTraitRef<'me, I> { | |
f035d41b | 674 | /// Show debug output for the `SeperatorTraitRef`. |
a2a8927a | 675 | pub fn debug<'a>(&'a self, interner: I) -> SeparatorTraitRefDebug<'a, 'me, I> { |
f9f354fc XL |
676 | SeparatorTraitRefDebug { |
677 | separator_trait_ref: self, | |
678 | interner, | |
679 | } | |
680 | } | |
681 | } | |
682 | ||
f035d41b XL |
683 | impl<I: Interner> Debug for LifetimeOutlives<I> { |
684 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
685 | write!(fmt, "{:?}: {:?}", self.a, self.b) | |
686 | } | |
687 | } | |
688 | ||
3dfed10e XL |
689 | impl<I: Interner> Debug for TypeOutlives<I> { |
690 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
691 | write!(fmt, "{:?}: {:?}", self.ty, self.lifetime) | |
692 | } | |
693 | } | |
694 | ||
f035d41b | 695 | /// Helper struct for showing debug output for projection types. |
f9f354fc XL |
696 | pub struct ProjectionTyDebug<'a, I: Interner> { |
697 | projection_ty: &'a ProjectionTy<I>, | |
a2a8927a | 698 | interner: I, |
f9f354fc XL |
699 | } |
700 | ||
701 | impl<'a, I: Interner> Debug for ProjectionTyDebug<'a, I> { | |
702 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
703 | let ProjectionTyDebug { | |
704 | projection_ty, | |
705 | interner, | |
706 | } = self; | |
707 | write!( | |
708 | fmt, | |
709 | "({:?}){:?}", | |
710 | projection_ty.associated_ty_id, | |
a2a8927a | 711 | projection_ty.substitution.with_angle(*interner) |
f9f354fc XL |
712 | ) |
713 | } | |
714 | } | |
715 | ||
716 | impl<I: Interner> ProjectionTy<I> { | |
f035d41b | 717 | /// Show debug output for the projection type. |
5e7ed085 | 718 | pub fn debug(&self, interner: I) -> ProjectionTyDebug<'_, I> { |
f9f354fc XL |
719 | ProjectionTyDebug { |
720 | projection_ty: self, | |
721 | interner, | |
722 | } | |
723 | } | |
724 | } | |
725 | ||
f035d41b | 726 | /// Helper struct for showing debug output for opaque types. |
f9f354fc XL |
727 | pub struct OpaqueTyDebug<'a, I: Interner> { |
728 | opaque_ty: &'a OpaqueTy<I>, | |
a2a8927a | 729 | interner: I, |
f9f354fc XL |
730 | } |
731 | ||
732 | impl<'a, I: Interner> Debug for OpaqueTyDebug<'a, I> { | |
733 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
734 | let OpaqueTyDebug { | |
735 | opaque_ty, | |
736 | interner, | |
737 | } = self; | |
738 | write!( | |
739 | fmt, | |
740 | "{:?}{:?}", | |
741 | opaque_ty.opaque_ty_id, | |
a2a8927a | 742 | opaque_ty.substitution.with_angle(*interner) |
f9f354fc XL |
743 | ) |
744 | } | |
745 | } | |
746 | ||
747 | impl<I: Interner> OpaqueTy<I> { | |
f035d41b | 748 | /// Show debug output for the opaque type. |
5e7ed085 | 749 | pub fn debug(&self, interner: I) -> OpaqueTyDebug<'_, I> { |
f9f354fc XL |
750 | OpaqueTyDebug { |
751 | opaque_ty: self, | |
752 | interner, | |
753 | } | |
754 | } | |
755 | } | |
756 | ||
f035d41b | 757 | /// Wraps debug output in angle brackets (`<>`). |
f9f354fc XL |
758 | pub struct Angle<'a, T>(pub &'a [T]); |
759 | ||
760 | impl<'a, T: Debug> Debug for Angle<'a, T> { | |
761 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
3dfed10e | 762 | if !self.0.is_empty() { |
f9f354fc XL |
763 | write!(fmt, "<")?; |
764 | for (index, elem) in self.0.iter().enumerate() { | |
765 | if index > 0 { | |
766 | write!(fmt, ", {:?}", elem)?; | |
767 | } else { | |
768 | write!(fmt, "{:?}", elem)?; | |
769 | } | |
770 | } | |
771 | write!(fmt, ">")?; | |
772 | } | |
773 | Ok(()) | |
774 | } | |
775 | } | |
776 | ||
777 | impl<I: Interner> Debug for Normalize<I> { | |
778 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
779 | write!(fmt, "Normalize({:?} -> {:?})", self.alias, self.ty) | |
780 | } | |
781 | } | |
782 | ||
783 | impl<I: Interner> Debug for AliasEq<I> { | |
784 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
785 | write!(fmt, "AliasEq({:?} = {:?})", self.alias, self.ty) | |
786 | } | |
787 | } | |
788 | ||
789 | impl<I: Interner> Debug for WhereClause<I> { | |
790 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
791 | match self { | |
792 | WhereClause::Implemented(tr) => write!(fmt, "Implemented({:?})", tr.with_colon()), | |
793 | WhereClause::AliasEq(a) => write!(fmt, "{:?}", a), | |
f035d41b | 794 | WhereClause::LifetimeOutlives(l_o) => write!(fmt, "{:?}", l_o), |
3dfed10e | 795 | WhereClause::TypeOutlives(t_o) => write!(fmt, "{:?}", t_o), |
f9f354fc XL |
796 | } |
797 | } | |
798 | } | |
799 | ||
800 | impl<I: Interner> Debug for FromEnv<I> { | |
801 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
802 | match self { | |
803 | FromEnv::Trait(t) => write!(fmt, "FromEnv({:?})", t.with_colon()), | |
804 | FromEnv::Ty(t) => write!(fmt, "FromEnv({:?})", t), | |
805 | } | |
806 | } | |
807 | } | |
808 | ||
809 | impl<I: Interner> Debug for WellFormed<I> { | |
810 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
811 | match self { | |
812 | WellFormed::Trait(t) => write!(fmt, "WellFormed({:?})", t.with_colon()), | |
813 | WellFormed::Ty(t) => write!(fmt, "WellFormed({:?})", t), | |
814 | } | |
815 | } | |
816 | } | |
817 | ||
818 | impl<I: Interner> Debug for DomainGoal<I> { | |
819 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
820 | match self { | |
821 | DomainGoal::Holds(n) => write!(fmt, "{:?}", n), | |
822 | DomainGoal::WellFormed(n) => write!(fmt, "{:?}", n), | |
823 | DomainGoal::FromEnv(n) => write!(fmt, "{:?}", n), | |
824 | DomainGoal::Normalize(n) => write!(fmt, "{:?}", n), | |
825 | DomainGoal::IsLocal(n) => write!(fmt, "IsLocal({:?})", n), | |
826 | DomainGoal::IsUpstream(n) => write!(fmt, "IsUpstream({:?})", n), | |
827 | DomainGoal::IsFullyVisible(n) => write!(fmt, "IsFullyVisible({:?})", n), | |
828 | DomainGoal::LocalImplAllowed(tr) => { | |
829 | write!(fmt, "LocalImplAllowed({:?})", tr.with_colon(),) | |
830 | } | |
3dfed10e | 831 | DomainGoal::Compatible => write!(fmt, "Compatible"), |
f9f354fc | 832 | DomainGoal::DownstreamType(n) => write!(fmt, "DownstreamType({:?})", n), |
3dfed10e | 833 | DomainGoal::Reveal => write!(fmt, "Reveal"), |
f035d41b | 834 | DomainGoal::ObjectSafe(n) => write!(fmt, "ObjectSafe({:?})", n), |
f9f354fc XL |
835 | } |
836 | } | |
837 | } | |
838 | ||
839 | impl<I: Interner> Debug for EqGoal<I> { | |
840 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
841 | write!(fmt, "({:?} = {:?})", self.a, self.b) | |
842 | } | |
843 | } | |
844 | ||
5869c6ff XL |
845 | impl<I: Interner> Debug for SubtypeGoal<I> { |
846 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
847 | write!(fmt, "({:?} <: {:?})", self.a, self.b) | |
848 | } | |
849 | } | |
850 | ||
f9f354fc XL |
851 | impl<T: HasInterner + Debug> Debug for Binders<T> { |
852 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
853 | let Binders { | |
854 | ref binders, | |
855 | ref value, | |
856 | } = *self; | |
857 | write!(fmt, "for{:?} ", binders.debug())?; | |
858 | Debug::fmt(value, fmt) | |
859 | } | |
860 | } | |
861 | ||
862 | impl<I: Interner> Debug for ProgramClauseData<I> { | |
863 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
f035d41b | 864 | write!(fmt, "{:?}", self.0) |
f9f354fc XL |
865 | } |
866 | } | |
867 | ||
868 | impl<I: Interner> Debug for Environment<I> { | |
869 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
870 | write!(fmt, "Env({:?})", self.clauses) | |
871 | } | |
872 | } | |
873 | ||
874 | impl<I: Interner> Debug for CanonicalVarKinds<I> { | |
875 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
876 | I::debug_canonical_var_kinds(self, fmt) | |
877 | .unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
878 | } | |
879 | } | |
880 | ||
881 | impl<T: HasInterner + Display> Canonical<T> { | |
f035d41b | 882 | /// Display the canonicalized item. |
5e7ed085 | 883 | pub fn display(&self, interner: T::Interner) -> CanonicalDisplay<'_, T> { |
f9f354fc XL |
884 | CanonicalDisplay { |
885 | canonical: self, | |
886 | interner, | |
887 | } | |
888 | } | |
889 | } | |
890 | ||
f035d41b | 891 | /// Helper struct for displaying canonicalized items. |
f9f354fc XL |
892 | pub struct CanonicalDisplay<'a, T: HasInterner> { |
893 | canonical: &'a Canonical<T>, | |
a2a8927a | 894 | interner: T::Interner, |
f9f354fc XL |
895 | } |
896 | ||
897 | impl<'a, T: HasInterner + Display> Display for CanonicalDisplay<'a, T> { | |
898 | fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { | |
899 | let Canonical { binders, value } = self.canonical; | |
900 | let interner = self.interner; | |
901 | let binders = binders.as_slice(interner); | |
902 | if binders.is_empty() { | |
903 | // Ordinarily, we try to print all binder levels, if they | |
904 | // are empty, but we can skip in this *particular* case | |
905 | // because we know that `Canonical` terms are never | |
906 | // supposed to contain free variables. In other words, | |
907 | // all "bound variables" that appear inside the canonical | |
908 | // value must reference values that appear in `binders`. | |
909 | write!(f, "{}", value)?; | |
910 | } else { | |
911 | write!(f, "for<")?; | |
912 | ||
913 | for (i, pk) in binders.iter().enumerate() { | |
914 | if i > 0 { | |
915 | write!(f, ",")?; | |
916 | } | |
f035d41b | 917 | write!(f, "?{}", pk.skip_kind())?; |
f9f354fc XL |
918 | } |
919 | ||
920 | write!(f, "> {{ {} }}", value)?; | |
921 | } | |
922 | ||
923 | Ok(()) | |
924 | } | |
925 | } | |
926 | ||
f035d41b XL |
927 | impl<I: Interner> Debug for GenericArgData<I> { |
928 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
929 | match self { | |
930 | GenericArgData::Ty(t) => write!(fmt, "Ty({:?})", t), | |
931 | GenericArgData::Lifetime(l) => write!(fmt, "Lifetime({:?})", l), | |
932 | GenericArgData::Const(c) => write!(fmt, "Const({:?})", c), | |
933 | } | |
934 | } | |
935 | } | |
936 | ||
937 | impl<I: Interner> Debug for VariableKind<I> { | |
938 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
939 | match self { | |
29967ef6 XL |
940 | VariableKind::Ty(TyVariableKind::General) => write!(fmt, "type"), |
941 | VariableKind::Ty(TyVariableKind::Integer) => write!(fmt, "integer type"), | |
942 | VariableKind::Ty(TyVariableKind::Float) => write!(fmt, "float type"), | |
f035d41b XL |
943 | VariableKind::Lifetime => write!(fmt, "lifetime"), |
944 | VariableKind::Const(ty) => write!(fmt, "const: {:?}", ty), | |
945 | } | |
946 | } | |
947 | } | |
948 | ||
949 | impl<I: Interner, T: Debug> Debug for WithKind<I, T> { | |
f9f354fc | 950 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { |
f035d41b XL |
951 | let value = self.skip_kind(); |
952 | match &self.kind { | |
29967ef6 XL |
953 | VariableKind::Ty(TyVariableKind::General) => write!(fmt, "{:?} with kind type", value), |
954 | VariableKind::Ty(TyVariableKind::Integer) => { | |
955 | write!(fmt, "{:?} with kind integer type", value) | |
956 | } | |
957 | VariableKind::Ty(TyVariableKind::Float) => { | |
958 | write!(fmt, "{:?} with kind float type", value) | |
959 | } | |
f035d41b XL |
960 | VariableKind::Lifetime => write!(fmt, "{:?} with kind lifetime", value), |
961 | VariableKind::Const(ty) => write!(fmt, "{:?} with kind {:?}", value, ty), | |
f9f354fc XL |
962 | } |
963 | } | |
964 | } | |
965 | ||
966 | impl<I: Interner> Debug for Constraint<I> { | |
967 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
968 | match self { | |
3dfed10e XL |
969 | Constraint::LifetimeOutlives(a, b) => write!(fmt, "{:?}: {:?}", a, b), |
970 | Constraint::TypeOutlives(ty, lifetime) => write!(fmt, "{:?}: {:?}", ty, lifetime), | |
f9f354fc XL |
971 | } |
972 | } | |
973 | } | |
974 | ||
975 | impl<I: Interner> Display for ConstrainedSubst<I> { | |
5e7ed085 | 976 | #[rustfmt::skip] |
f9f354fc XL |
977 | fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { |
978 | let ConstrainedSubst { subst, constraints } = self; | |
979 | ||
5e7ed085 FG |
980 | let mut first = true; |
981 | ||
982 | let subst = format!("{}", Fmt(|f| Display::fmt(subst, f))); | |
983 | if subst != "[]" { | |
984 | write!(f, "substitution {}", subst)?; | |
985 | first = false; | |
986 | } | |
987 | ||
988 | let constraints = format!("{}", Fmt(|f| Debug::fmt(constraints, f))); | |
989 | if constraints != "[]" { | |
990 | if !first { write!(f, ", ")?; } | |
991 | write!(f, "lifetime constraints {}", constraints)?; | |
992 | first = false; | |
993 | } | |
994 | ||
995 | let _ = first; | |
996 | Ok(()) | |
f9f354fc XL |
997 | } |
998 | } | |
999 | ||
1000 | impl<I: Interner> Substitution<I> { | |
1001 | /// Displays the substitution in the form `< P0, .. Pn >`, or (if | |
1002 | /// the substitution is empty) as an empty string. | |
a2a8927a | 1003 | pub fn with_angle(&self, interner: I) -> Angle<'_, GenericArg<I>> { |
3dfed10e | 1004 | Angle(self.as_slice(interner)) |
f9f354fc XL |
1005 | } |
1006 | } | |
1007 | ||
1008 | impl<I: Interner> Debug for Substitution<I> { | |
1009 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
1010 | Display::fmt(self, fmt) | |
1011 | } | |
1012 | } | |
5869c6ff XL |
1013 | |
1014 | impl<I: Interner> Debug for Variances<I> { | |
1015 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { | |
1016 | I::debug_variances(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) | |
1017 | } | |
1018 | } |