1 //! Debug impls for types.
3 use std
::fmt
::{self, Debug, Display, Error, Formatter}
;
7 /// Wrapper to allow forwarding to `Display::fmt`, `Debug::fmt`, etc.
8 pub struct Fmt
<F
>(pub F
)
10 F
: Fn(&mut fmt
::Formatter
<'_
>) -> fmt
::Result
;
12 impl<F
> fmt
::Display
for Fmt
<F
>
14 F
: Fn(&mut fmt
::Formatter
<'_
>) -> fmt
::Result
,
16 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
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))
27 impl<I
: Interner
> Debug
for AdtId
<I
> {
28 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
29 I
::debug_adt_id(*self, fmt
).unwrap_or_else(|| write
!(fmt
, "AdtId({:?})", self.0))
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))
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))
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))
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))
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))
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
))
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
))
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
))
84 impl<I
: Interner
> Debug
for ConcreteConst
<I
> {
85 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
86 write
!(fmt
, "{:?}", self.interned
)
90 impl<I
: Interner
> Debug
for GenericArg
<I
> {
91 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
92 I
::debug_generic_arg(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
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
))
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
))
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(?)"))
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
))
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
))
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
))
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(?)"))
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(?)"))
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
))
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")
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")
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
))
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))
181 impl Display
for UniverseIndex
{
182 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
183 write
!(fmt
, "U{}", self.counter
)
187 impl Debug
for UniverseIndex
{
188 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
189 write
!(fmt
, "U{}", self.counter
)
193 impl<I
: Interner
> Debug
for TyData
<I
> {
194 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
199 impl<I
: Interner
> Debug
for TyKind
<I
> {
200 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
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
)
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
)
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
),
226 TyKind
::Raw(mutability
, ty
) => match mutability
{
227 Mutability
::Mut
=> write
!(fmt
, "(*mut {:?})", ty
),
228 Mutability
::Not
=> write
!(fmt
, "(*const {:?})", ty
),
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
)
235 TyKind
::Generator(generator
, substitution
) => {
236 write
!(fmt
, "{:?}<{:?}>", generator
, substitution
)
238 TyKind
::GeneratorWitness(witness
, substitution
) => {
239 write
!(fmt
, "{:?}<{:?}>", witness
, substitution
)
241 TyKind
::Foreign(foreign_ty
) => write
!(fmt
, "{:?}", foreign_ty
),
242 TyKind
::Error
=> write
!(fmt
, "{{error}}"),
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
)
254 impl Debug
for DebruijnIndex
{
255 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
256 let DebruijnIndex { depth }
= self;
257 write
!(fmt
, "^{}", depth
)
261 impl<I
: Interner
> Debug
for DynTy
<I
> {
262 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
263 let DynTy { bounds, lifetime }
= self;
264 write
!(fmt
, "dyn {:?} + {:?}", bounds
, lifetime
)
268 impl Debug
for InferenceVar
{
269 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
270 write
!(fmt
, "?{}", self.index
)
274 impl<I
: Interner
> Debug
for FnSubst
<I
> {
275 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
276 write
!(fmt
, "{:?}", self.0)
280 impl<I
: Interner
> Debug
for FnPointer
<I
> {
281 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
282 // FIXME -- we should introduce some names or something here
290 "{}{:?} for<{}> {:?}",
292 Safety
::Unsafe
=> "unsafe ",
302 impl<I
: Interner
> Debug
for LifetimeData
<I
> {
303 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
305 LifetimeData
::BoundVar(db
) => write
!(fmt
, "'{:?}", db
),
306 LifetimeData
::InferenceVar(var
) => write
!(fmt
, "'{:?}", var
),
307 LifetimeData
::Placeholder(index
) => write
!(fmt
, "'{:?}", index
),
308 LifetimeData
::Static
=> write
!(fmt
, "'static"),
309 LifetimeData
::Empty(UniverseIndex
::ROOT
) => write
!(fmt
, "'<empty>"),
310 LifetimeData
::Empty(universe
) => write
!(fmt
, "'<empty:{:?}>", universe
),
311 LifetimeData
::Erased
=> write
!(fmt
, "'<erased>"),
312 LifetimeData
::Phantom(..) => unreachable
!(),
317 impl<I
: Interner
> VariableKinds
<I
> {
318 fn debug(&self) -> VariableKindsDebug
<'_
, I
> {
319 VariableKindsDebug(self)
322 /// Helper method for debugging variable kinds.
323 pub fn inner_debug(&self, interner
: I
) -> VariableKindsInnerDebug
<'_
, I
> {
324 VariableKindsInnerDebug
{
325 variable_kinds
: self,
331 struct VariableKindsDebug
<'a
, I
: Interner
>(&'a VariableKinds
<I
>);
333 impl<'a
, I
: Interner
> Debug
for VariableKindsDebug
<'a
, I
> {
334 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
335 I
::debug_variable_kinds_with_angles(self.0, fmt
)
336 .unwrap_or_else(|| write
!(fmt
, "{:?}", self.0.interned
))
340 /// Helper struct for showing debug output for `VariableKinds`.
341 pub struct VariableKindsInnerDebug
<'a
, I
: Interner
> {
342 variable_kinds
: &'a VariableKinds
<I
>,
346 impl<'a
, I
: Interner
> Debug
for VariableKindsInnerDebug
<'a
, I
> {
347 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
348 // NB: We print variable kinds as a list delimited by `<>`,
349 // like `<K1, K2, ..>`. This is because variable kind lists
350 // are always associated with binders like `forall<type> {
353 for (index
, binder
) in self.variable_kinds
.iter(self.interner
).enumerate() {
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")?
,
361 VariableKind
::Lifetime
=> write
!(fmt
, "lifetime")?
,
362 VariableKind
::Const(ty
) => write
!(fmt
, "const: {:?}", ty
)?
,
369 impl<I
: Interner
> Debug
for ConstData
<I
> {
370 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
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
),
380 impl<I
: Interner
> Debug
for GoalData
<I
> {
381 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
383 GoalData
::Quantified(qkind
, ref subgoal
) => write
!(
385 "{:?}{:?} {{ {:?} }}",
387 subgoal
.binders
.debug(),
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
),
394 GoalData
::SubtypeGoal(ref wc
) => write
!(fmt
, "{:?}", wc
),
395 GoalData
::DomainGoal(ref wc
) => write
!(fmt
, "{:?}", wc
),
396 GoalData
::CannotProve
=> write
!(fmt
, r
"¯\_(ツ)_/¯"),
401 /// Helper struct for showing debug output for `Goals`.
402 pub struct GoalsDebug
<'a
, I
: Interner
> {
407 impl<'a
, I
: Interner
> Debug
for GoalsDebug
<'a
, I
> {
408 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
410 for (goal
, index
) in self.goals
.iter(self.interner
).zip(0..) {
414 write
!(fmt
, "{:?}", goal
)?
;
421 impl<I
: Interner
> Goals
<I
> {
422 /// Show debug output for `Goals`.
423 pub fn debug(&self, interner
: I
) -> GoalsDebug
<'_
, I
> {
431 /// Helper struct for showing debug output for `GenericArgData`.
432 pub struct GenericArgDataInnerDebug
<'a
, I
: Interner
>(&'a GenericArgData
<I
>);
434 impl<'a
, I
: Interner
> Debug
for GenericArgDataInnerDebug
<'a
, I
> {
435 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
437 GenericArgData
::Ty(n
) => write
!(fmt
, "{:?}", n
),
438 GenericArgData
::Lifetime(n
) => write
!(fmt
, "{:?}", n
),
439 GenericArgData
::Const(n
) => write
!(fmt
, "{:?}", n
),
444 impl<I
: Interner
> GenericArgData
<I
> {
445 /// Helper method for debugging `GenericArgData`.
446 pub fn inner_debug(&self) -> GenericArgDataInnerDebug
<'_
, I
> {
447 GenericArgDataInnerDebug(self)
451 /// Helper struct for showing debug output for program clause implications.
452 pub struct ProgramClauseImplicationDebug
<'a
, I
: Interner
> {
453 pci
: &'a ProgramClauseImplication
<I
>,
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
)?
;
462 let conditions
= pci
.conditions
.as_slice(*interner
);
464 let conds
= conditions
.len();
469 write
!(fmt
, " :- ")?
;
470 for cond
in &conditions
[..conds
- 1] {
471 write
!(fmt
, "{:?}, ", cond
)?
;
473 write
!(fmt
, "{:?}", conditions
[conds
- 1])
477 impl<I
: Interner
> ProgramClauseImplication
<I
> {
478 /// Show debug output for the program clause implication.
479 pub fn debug(&self, interner
: I
) -> ProgramClauseImplicationDebug
<'_
, I
> {
480 ProgramClauseImplicationDebug
{
487 /// Helper struct for showing debug output for application types.
488 pub struct TyKindDebug
<'a
, I
: Interner
> {
493 impl<'a
, I
: Interner
> Debug
for TyKindDebug
<'a
, I
> {
494 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
495 let interner
= self.interner
;
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
))
508 TyKind
::AssociatedType(assoc_ty
, substitution
) => {
509 write
!(fmt
, "{:?}{:?}", assoc_ty
, substitution
.with_angle(interner
))
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
))
516 TyKind
::OpaqueType(opaque_ty
, substitution
) => write
!(
520 substitution
.with_angle(interner
)
522 TyKind
::Slice(ty
) => write
!(fmt
, "[{:?}]", ty
),
523 TyKind
::FnDef(fn_def
, substitution
) => {
524 write
!(fmt
, "{:?}{:?}", fn_def
, substitution
.with_angle(interner
))
526 TyKind
::Ref(mutability
, lifetime
, ty
) => match mutability
{
527 Mutability
::Mut
=> write
!(fmt
, "(&{:?} mut {:?})", lifetime
, ty
),
528 Mutability
::Not
=> write
!(fmt
, "(&{:?} {:?})", lifetime
, ty
),
530 TyKind
::Raw(mutability
, ty
) => match mutability
{
531 Mutability
::Mut
=> write
!(fmt
, "(*mut {:?})", ty
),
532 Mutability
::Not
=> write
!(fmt
, "(*const {:?})", ty
),
534 TyKind
::Never
=> write
!(fmt
, "Never"),
535 TyKind
::Array(ty
, const_
) => write
!(fmt
, "[{:?}; {:?}]", ty
, const_
),
536 TyKind
::Closure(id
, substitution
) => write
!(
538 "{{closure:{:?}}}{:?}",
540 substitution
.with_angle(interner
)
542 TyKind
::Generator(generator
, substitution
) => write
!(
546 substitution
.with_angle(interner
)
548 TyKind
::GeneratorWitness(witness
, substitution
) => {
549 write
!(fmt
, "{:?}{:?}", witness
, substitution
.with_angle(interner
))
551 TyKind
::Foreign(foreign_ty
) => write
!(fmt
, "{:?}", foreign_ty
,),
552 TyKind
::Error
=> write
!(fmt
, "{{error}}"),
557 impl<I
: Interner
> TyKind
<I
> {
558 /// Show debug output for the application type.
559 pub fn debug(&self, interner
: I
) -> TyKindDebug
<'_
, I
> {
560 TyKindDebug { ty: self, interner }
564 /// Helper struct for showing debug output for substitutions.
565 pub struct SubstitutionDebug
<'a
, I
: Interner
> {
566 substitution
: &'a Substitution
<I
>,
570 impl<'a
, I
: Interner
> Debug
for SubstitutionDebug
<'a
, I
> {
571 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
572 let SubstitutionDebug
{
576 let mut first
= true;
580 for (index
, value
) in substitution
.iter(*interner
).enumerate() {
587 write
!(fmt
, "?{} := {:?}", index
, value
)?
;
596 impl<I
: Interner
> Substitution
<I
> {
597 /// Show debug output for the substitution.
598 pub fn debug(&self, interner
: I
) -> SubstitutionDebug
<'_
, I
> {
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
)
613 impl<I
: Interner
> TraitRef
<I
> {
614 /// Returns a "Debuggable" type that prints like `P0 as Trait<P1..>`.
615 pub fn with_as(&self) -> impl std
::fmt
::Debug
+ '_
{
622 /// Returns a "Debuggable" type that prints like `P0: Trait<P1..>`.
623 pub fn with_colon(&self) -> impl std
::fmt
::Debug
+ '_
{
631 impl<I
: Interner
> Debug
for TraitRef
<I
> {
632 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
633 Debug
::fmt(&self.with_as(), fmt
)
637 /// Trait ref with associated separator used for debug output.
638 pub struct SeparatorTraitRef
<'me
, I
: Interner
> {
639 /// The `TraitRef` itself.
640 pub trait_ref
: &'me TraitRef
<I
>,
642 /// The separator used for displaying the `TraitRef`.
643 pub separator
: &'me
str,
646 /// Helper struct for showing debug output for the `SeperatorTraitRef`.
647 pub struct SeparatorTraitRefDebug
<'a
, 'me
, I
: Interner
> {
648 separator_trait_ref
: &'a SeparatorTraitRef
<'me
, I
>,
652 impl<'a
, 'me
, I
: Interner
> Debug
for SeparatorTraitRefDebug
<'a
, 'me
, I
> {
653 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
654 let SeparatorTraitRefDebug
{
658 let parameters
= separator_trait_ref
661 .as_slice(*interner
);
666 separator_trait_ref
.separator
,
667 separator_trait_ref
.trait_ref
.trait_id
,
668 Angle(¶meters
[1..])
673 impl<'me
, I
: Interner
> SeparatorTraitRef
<'me
, I
> {
674 /// Show debug output for the `SeperatorTraitRef`.
675 pub fn debug
<'a
>(&'a
self, interner
: I
) -> SeparatorTraitRefDebug
<'a
, 'me
, I
> {
676 SeparatorTraitRefDebug
{
677 separator_trait_ref
: self,
683 impl<I
: Interner
> Debug
for LifetimeOutlives
<I
> {
684 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
685 write
!(fmt
, "{:?}: {:?}", self.a
, self.b
)
689 impl<I
: Interner
> Debug
for TypeOutlives
<I
> {
690 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
691 write
!(fmt
, "{:?}: {:?}", self.ty
, self.lifetime
)
695 /// Helper struct for showing debug output for projection types.
696 pub struct ProjectionTyDebug
<'a
, I
: Interner
> {
697 projection_ty
: &'a ProjectionTy
<I
>,
701 impl<'a
, I
: Interner
> Debug
for ProjectionTyDebug
<'a
, I
> {
702 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
703 let ProjectionTyDebug
{
710 projection_ty
.associated_ty_id
,
711 projection_ty
.substitution
.with_angle(*interner
)
716 impl<I
: Interner
> ProjectionTy
<I
> {
717 /// Show debug output for the projection type.
718 pub fn debug(&self, interner
: I
) -> ProjectionTyDebug
<'_
, I
> {
726 /// Helper struct for showing debug output for opaque types.
727 pub struct OpaqueTyDebug
<'a
, I
: Interner
> {
728 opaque_ty
: &'a OpaqueTy
<I
>,
732 impl<'a
, I
: Interner
> Debug
for OpaqueTyDebug
<'a
, I
> {
733 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
741 opaque_ty
.opaque_ty_id
,
742 opaque_ty
.substitution
.with_angle(*interner
)
747 impl<I
: Interner
> OpaqueTy
<I
> {
748 /// Show debug output for the opaque type.
749 pub fn debug(&self, interner
: I
) -> OpaqueTyDebug
<'_
, I
> {
757 /// Wraps debug output in angle brackets (`<>`).
758 pub struct Angle
<'a
, T
>(pub &'a
[T
]);
760 impl<'a
, T
: Debug
> Debug
for Angle
<'a
, T
> {
761 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
762 if !self.0.is_empty
() {
764 for (index
, elem
) in self.0.iter
().enumerate() {
766 write
!(fmt
, ", {:?}", elem
)?
;
768 write
!(fmt
, "{:?}", elem
)?
;
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
)
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
)
789 impl<I
: Interner
> Debug
for WhereClause
<I
> {
790 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
792 WhereClause
::Implemented(tr
) => write
!(fmt
, "Implemented({:?})", tr
.with_colon()),
793 WhereClause
::AliasEq(a
) => write
!(fmt
, "{:?}", a
),
794 WhereClause
::LifetimeOutlives(l_o
) => write
!(fmt
, "{:?}", l_o
),
795 WhereClause
::TypeOutlives(t_o
) => write
!(fmt
, "{:?}", t_o
),
800 impl<I
: Interner
> Debug
for FromEnv
<I
> {
801 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
803 FromEnv
::Trait(t
) => write
!(fmt
, "FromEnv({:?})", t
.with_colon()),
804 FromEnv
::Ty(t
) => write
!(fmt
, "FromEnv({:?})", t
),
809 impl<I
: Interner
> Debug
for WellFormed
<I
> {
810 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
812 WellFormed
::Trait(t
) => write
!(fmt
, "WellFormed({:?})", t
.with_colon()),
813 WellFormed
::Ty(t
) => write
!(fmt
, "WellFormed({:?})", t
),
818 impl<I
: Interner
> Debug
for DomainGoal
<I
> {
819 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
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(),)
831 DomainGoal
::Compatible
=> write
!(fmt
, "Compatible"),
832 DomainGoal
::DownstreamType(n
) => write
!(fmt
, "DownstreamType({:?})", n
),
833 DomainGoal
::Reveal
=> write
!(fmt
, "Reveal"),
834 DomainGoal
::ObjectSafe(n
) => write
!(fmt
, "ObjectSafe({:?})", n
),
839 impl<I
: Interner
> Debug
for EqGoal
<I
> {
840 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
841 write
!(fmt
, "({:?} = {:?})", self.a
, self.b
)
845 impl<I
: Interner
> Debug
for SubtypeGoal
<I
> {
846 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
847 write
!(fmt
, "({:?} <: {:?})", self.a
, self.b
)
851 impl<T
: HasInterner
+ Debug
> Debug
for Binders
<T
> {
852 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
857 write
!(fmt
, "for{:?} ", binders
.debug())?
;
858 Debug
::fmt(value
, fmt
)
862 impl<I
: Interner
> Debug
for ProgramClauseData
<I
> {
863 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
864 write
!(fmt
, "{:?}", self.0)
868 impl<I
: Interner
> Debug
for Environment
<I
> {
869 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
870 write
!(fmt
, "Env({:?})", self.clauses
)
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
))
881 impl<T
: HasInterner
+ Display
> Canonical
<T
> {
882 /// Display the canonicalized item.
883 pub fn display(&self, interner
: T
::Interner
) -> CanonicalDisplay
<'_
, T
> {
891 /// Helper struct for displaying canonicalized items.
892 pub struct CanonicalDisplay
<'a
, T
: HasInterner
> {
893 canonical
: &'a Canonical
<T
>,
894 interner
: T
::Interner
,
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
)?
;
913 for (i
, pk
) in binders
.iter().enumerate() {
917 write
!(f
, "?{}", pk
.skip_kind())?
;
920 write
!(f
, "> {{ {} }}", value
)?
;
927 impl<I
: Interner
> Debug
for GenericArgData
<I
> {
928 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
930 GenericArgData
::Ty(t
) => write
!(fmt
, "Ty({:?})", t
),
931 GenericArgData
::Lifetime(l
) => write
!(fmt
, "Lifetime({:?})", l
),
932 GenericArgData
::Const(c
) => write
!(fmt
, "Const({:?})", c
),
937 impl<I
: Interner
> Debug
for VariableKind
<I
> {
938 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
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"),
943 VariableKind
::Lifetime
=> write
!(fmt
, "lifetime"),
944 VariableKind
::Const(ty
) => write
!(fmt
, "const: {:?}", ty
),
949 impl<I
: Interner
, T
: Debug
> Debug
for WithKind
<I
, T
> {
950 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
951 let value
= self.skip_kind();
953 VariableKind
::Ty(TyVariableKind
::General
) => write
!(fmt
, "{:?} with kind type", value
),
954 VariableKind
::Ty(TyVariableKind
::Integer
) => {
955 write
!(fmt
, "{:?} with kind integer type", value
)
957 VariableKind
::Ty(TyVariableKind
::Float
) => {
958 write
!(fmt
, "{:?} with kind float type", value
)
960 VariableKind
::Lifetime
=> write
!(fmt
, "{:?} with kind lifetime", value
),
961 VariableKind
::Const(ty
) => write
!(fmt
, "{:?} with kind {:?}", value
, ty
),
966 impl<I
: Interner
> Debug
for Constraint
<I
> {
967 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
969 Constraint
::LifetimeOutlives(a
, b
) => write
!(fmt
, "{:?}: {:?}", a
, b
),
970 Constraint
::TypeOutlives(ty
, lifetime
) => write
!(fmt
, "{:?}: {:?}", ty
, lifetime
),
975 impl<I
: Interner
> Display
for ConstrainedSubst
<I
> {
977 fn fmt(&self, f
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
978 let ConstrainedSubst { subst, constraints }
= self;
980 let mut first
= true;
982 let subst
= format
!("{}", Fmt(|f
| Display
::fmt(subst
, f
)));
984 write
!(f
, "substitution {}", subst
)?
;
988 let constraints
= format
!("{}", Fmt(|f
| Debug
::fmt(constraints
, f
)));
989 if constraints
!= "[]" {
990 if !first { write!(f, ", ")?; }
991 write
!(f
, "lifetime constraints {}", constraints
)?
;
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.
1003 pub fn with_angle(&self, interner
: I
) -> Angle
<'_
, GenericArg
<I
>> {
1004 Angle(self.as_slice(interner
))
1008 impl<I
: Interner
> Debug
for Substitution
<I
> {
1009 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
1010 Display
::fmt(self, fmt
)
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
))