1 //! Debug impls for types.
3 use std
::fmt
::{Debug, Display, Error, Formatter}
;
7 impl<I
: Interner
> Debug
for TraitId
<I
> {
8 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
9 I
::debug_trait_id(*self, fmt
).unwrap_or_else(|| write
!(fmt
, "TraitId({:?})", self.0))
13 impl<I
: Interner
> Debug
for AdtId
<I
> {
14 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
15 I
::debug_adt_id(*self, fmt
).unwrap_or_else(|| write
!(fmt
, "AdtId({:?})", self.0))
19 impl<I
: Interner
> Debug
for AssocTypeId
<I
> {
20 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
21 I
::debug_assoc_type_id(*self, fmt
)
22 .unwrap_or_else(|| write
!(fmt
, "AssocTypeId({:?})", self.0))
26 impl<I
: Interner
> Debug
for FnDefId
<I
> {
27 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> std
::fmt
::Result
{
28 I
::debug_fn_def_id(*self, fmt
).unwrap_or_else(|| write
!(fmt
, "FnDefId({:?})", self.0))
32 impl<I
: Interner
> Debug
for ClosureId
<I
> {
33 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> std
::fmt
::Result
{
34 I
::debug_closure_id(*self, fmt
).unwrap_or_else(|| write
!(fmt
, "ClosureId({:?})", self.0))
38 impl<I
: Interner
> Debug
for GeneratorId
<I
> {
39 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> std
::fmt
::Result
{
40 I
::debug_generator_id(*self, fmt
)
41 .unwrap_or_else(|| write
!(fmt
, "GeneratorId({:?})", self.0))
45 impl<I
: Interner
> Debug
for ForeignDefId
<I
> {
46 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> std
::fmt
::Result
{
47 I
::debug_foreign_def_id(*self, fmt
)
48 .unwrap_or_else(|| write
!(fmt
, "ForeignDefId({:?})", self.0))
52 impl<I
: Interner
> Debug
for Ty
<I
> {
53 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
54 I
::debug_ty(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
58 impl<I
: Interner
> Debug
for Lifetime
<I
> {
59 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
60 I
::debug_lifetime(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
64 impl<I
: Interner
> Debug
for Const
<I
> {
65 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
66 I
::debug_const(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
70 impl<I
: Interner
> Debug
for ConcreteConst
<I
> {
71 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
72 write
!(fmt
, "{:?}", self.interned
)
76 impl<I
: Interner
> Debug
for GenericArg
<I
> {
77 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
78 I
::debug_generic_arg(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
82 impl<I
: Interner
> Debug
for Goal
<I
> {
83 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
84 I
::debug_goal(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
88 impl<I
: Interner
> Debug
for Goals
<I
> {
89 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
90 I
::debug_goals(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
94 impl<I
: Interner
> Debug
for ProgramClauseImplication
<I
> {
95 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
96 I
::debug_program_clause_implication(self, fmt
)
97 .unwrap_or_else(|| write
!(fmt
, "ProgramClauseImplication(?)"))
101 impl<I
: Interner
> Debug
for ProgramClause
<I
> {
102 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
103 I
::debug_program_clause(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
107 impl<I
: Interner
> Debug
for ProgramClauses
<I
> {
108 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
109 I
::debug_program_clauses(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
113 impl<I
: Interner
> Debug
for Constraints
<I
> {
114 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
115 I
::debug_constraints(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
119 impl<I
: Interner
> Debug
for SeparatorTraitRef
<'_
, I
> {
120 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
121 I
::debug_separator_trait_ref(self, fmt
)
122 .unwrap_or_else(|| write
!(fmt
, "SeparatorTraitRef(?)"))
126 impl<I
: Interner
> Debug
for AliasTy
<I
> {
127 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
128 I
::debug_alias(self, fmt
).unwrap_or_else(|| write
!(fmt
, "AliasTy(?)"))
132 impl<I
: Interner
> Debug
for QuantifiedWhereClauses
<I
> {
133 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
134 I
::debug_quantified_where_clauses(self, fmt
)
135 .unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
139 impl<I
: Interner
> Debug
for ProjectionTy
<I
> {
140 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
141 I
::debug_projection_ty(self, fmt
).unwrap_or_else(|| {
142 unimplemented
!("cannot format ProjectionTy without setting Program in tls")
147 impl<I
: Interner
> Debug
for OpaqueTy
<I
> {
148 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
149 I
::debug_opaque_ty(self, fmt
).unwrap_or_else(|| {
150 unimplemented
!("cannot format OpaqueTy without setting Program in tls")
155 impl<I
: Interner
> Display
for Substitution
<I
> {
156 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
157 I
::debug_substitution(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
161 impl<I
: Interner
> Debug
for OpaqueTyId
<I
> {
162 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
163 I
::debug_opaque_ty_id(*self, fmt
).unwrap_or_else(|| write
!(fmt
, "OpaqueTyId({:?})", self.0))
167 impl Display
for UniverseIndex
{
168 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
169 write
!(fmt
, "U{}", self.counter
)
173 impl Debug
for UniverseIndex
{
174 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
175 write
!(fmt
, "U{}", self.counter
)
179 impl<I
: Interner
> Debug
for TyData
<I
> {
180 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
185 impl<I
: Interner
> Debug
for TyKind
<I
> {
186 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
188 TyKind
::BoundVar(db
) => write
!(fmt
, "{:?}", db
),
189 TyKind
::Dyn(clauses
) => write
!(fmt
, "{:?}", clauses
),
190 TyKind
::InferenceVar(var
, TyVariableKind
::General
) => write
!(fmt
, "{:?}", var
),
191 TyKind
::InferenceVar(var
, TyVariableKind
::Integer
) => write
!(fmt
, "{:?}i", var
),
192 TyKind
::InferenceVar(var
, TyVariableKind
::Float
) => write
!(fmt
, "{:?}f", var
),
193 TyKind
::Alias(alias
) => write
!(fmt
, "{:?}", alias
),
194 TyKind
::Placeholder(index
) => write
!(fmt
, "{:?}", index
),
195 TyKind
::Function(function
) => write
!(fmt
, "{:?}", function
),
196 TyKind
::Adt(id
, substitution
) => write
!(fmt
, "{:?}<{:?}>", id
, substitution
),
197 TyKind
::AssociatedType(assoc_ty
, substitution
) => {
198 write
!(fmt
, "{:?}<{:?}>", assoc_ty
, substitution
)
200 TyKind
::Scalar(scalar
) => write
!(fmt
, "{:?}", scalar
),
201 TyKind
::Str
=> write
!(fmt
, "Str"),
202 TyKind
::Tuple(arity
, substitution
) => write
!(fmt
, "{:?}<{:?}>", arity
, substitution
),
203 TyKind
::OpaqueType(opaque_ty
, substitution
) => {
204 write
!(fmt
, "!{:?}<{:?}>", opaque_ty
, substitution
)
206 TyKind
::Slice(substitution
) => write
!(fmt
, "{{slice}}<{:?}>", substitution
),
207 TyKind
::FnDef(fn_def
, substitution
) => write
!(fmt
, "{:?}<{:?}>", fn_def
, substitution
),
208 TyKind
::Ref(mutability
, lifetime
, ty
) => match mutability
{
209 Mutability
::Mut
=> write
!(fmt
, "(&{:?} mut {:?})", lifetime
, ty
),
210 Mutability
::Not
=> write
!(fmt
, "(&{:?} {:?})", lifetime
, ty
),
212 TyKind
::Raw(mutability
, ty
) => match mutability
{
213 Mutability
::Mut
=> write
!(fmt
, "(*mut {:?})", ty
),
214 Mutability
::Not
=> write
!(fmt
, "(*const {:?})", ty
),
216 TyKind
::Never
=> write
!(fmt
, "Never"),
217 TyKind
::Array(ty
, const_
) => write
!(fmt
, "[{:?}; {:?}]", ty
, const_
),
218 TyKind
::Closure(id
, substitution
) => {
219 write
!(fmt
, "{{closure:{:?}}}<{:?}>", id
, substitution
)
221 TyKind
::Generator(generator
, substitution
) => {
222 write
!(fmt
, "{:?}<{:?}>", generator
, substitution
)
224 TyKind
::GeneratorWitness(witness
, substitution
) => {
225 write
!(fmt
, "{:?}<{:?}>", witness
, substitution
)
227 TyKind
::Foreign(foreign_ty
) => write
!(fmt
, "{:?}", foreign_ty
),
228 TyKind
::Error
=> write
!(fmt
, "{{error}}"),
233 impl Debug
for BoundVar
{
234 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
235 let BoundVar { debruijn, index }
= self;
236 write
!(fmt
, "{:?}.{:?}", debruijn
, index
)
240 impl Debug
for DebruijnIndex
{
241 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
242 let DebruijnIndex { depth }
= self;
243 write
!(fmt
, "^{}", depth
)
247 impl<I
: Interner
> Debug
for DynTy
<I
> {
248 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
249 let DynTy { bounds, lifetime }
= self;
250 write
!(fmt
, "dyn {:?} + {:?}", bounds
, lifetime
)
254 impl Debug
for InferenceVar
{
255 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
256 write
!(fmt
, "?{}", self.index
)
260 impl<I
: Interner
> Debug
for FnSubst
<I
> {
261 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
262 write
!(fmt
, "{:?}", self.0)
266 impl<I
: Interner
> Debug
for FnPointer
<I
> {
267 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
268 // FIXME -- we should introduce some names or something here
276 "{}{:?} for<{}> {:?}",
278 Safety
::Unsafe
=> "unsafe ",
288 impl<I
: Interner
> Debug
for LifetimeData
<I
> {
289 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
291 LifetimeData
::BoundVar(db
) => write
!(fmt
, "'{:?}", db
),
292 LifetimeData
::InferenceVar(var
) => write
!(fmt
, "'{:?}", var
),
293 LifetimeData
::Placeholder(index
) => write
!(fmt
, "'{:?}", index
),
294 LifetimeData
::Static
=> write
!(fmt
, "'static"),
295 LifetimeData
::Empty(UniverseIndex
::ROOT
) => write
!(fmt
, "'<empty>"),
296 LifetimeData
::Empty(universe
) => write
!(fmt
, "'<empty:{:?}>", universe
),
297 LifetimeData
::Erased
=> write
!(fmt
, "'<erased>"),
298 LifetimeData
::Phantom(..) => unreachable
!(),
303 impl<I
: Interner
> VariableKinds
<I
> {
304 fn debug(&self) -> VariableKindsDebug
<'_
, I
> {
305 VariableKindsDebug(self)
308 /// Helper method for debugging variable kinds.
309 pub fn inner_debug
<'a
>(&'a
self, interner
: &'a I
) -> VariableKindsInnerDebug
<'a
, I
> {
310 VariableKindsInnerDebug
{
311 variable_kinds
: self,
317 struct VariableKindsDebug
<'a
, I
: Interner
>(&'a VariableKinds
<I
>);
319 impl<'a
, I
: Interner
> Debug
for VariableKindsDebug
<'a
, I
> {
320 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
321 I
::debug_variable_kinds_with_angles(self.0, fmt
)
322 .unwrap_or_else(|| write
!(fmt
, "{:?}", self.0.interned
))
326 /// Helper struct for showing debug output for `VariableKinds`.
327 pub struct VariableKindsInnerDebug
<'a
, I
: Interner
> {
328 variable_kinds
: &'a VariableKinds
<I
>,
332 impl<'a
, I
: Interner
> Debug
for VariableKindsInnerDebug
<'a
, I
> {
333 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
334 // NB: We print variable kinds as a list delimited by `<>`,
335 // like `<K1, K2, ..>`. This is because variable kind lists
336 // are always associated with binders like `forall<type> {
339 for (index
, binder
) in self.variable_kinds
.iter(self.interner
).enumerate() {
344 VariableKind
::Ty(TyVariableKind
::General
) => write
!(fmt
, "type")?
,
345 VariableKind
::Ty(TyVariableKind
::Integer
) => write
!(fmt
, "integer type")?
,
346 VariableKind
::Ty(TyVariableKind
::Float
) => write
!(fmt
, "float type")?
,
347 VariableKind
::Lifetime
=> write
!(fmt
, "lifetime")?
,
348 VariableKind
::Const(ty
) => write
!(fmt
, "const: {:?}", ty
)?
,
355 impl<I
: Interner
> Debug
for ConstData
<I
> {
356 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
358 ConstValue
::BoundVar(db
) => write
!(fmt
, "{:?}", db
),
359 ConstValue
::InferenceVar(var
) => write
!(fmt
, "{:?}", var
),
360 ConstValue
::Placeholder(index
) => write
!(fmt
, "{:?}", index
),
361 ConstValue
::Concrete(evaluated
) => write
!(fmt
, "{:?}", evaluated
),
366 impl<I
: Interner
> Debug
for GoalData
<I
> {
367 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
369 GoalData
::Quantified(qkind
, ref subgoal
) => write
!(
371 "{:?}{:?} {{ {:?} }}",
373 subgoal
.binders
.debug(),
376 GoalData
::Implies(ref wc
, ref g
) => write
!(fmt
, "if ({:?}) {{ {:?} }}", wc
, g
),
377 GoalData
::All(ref goals
) => write
!(fmt
, "all{:?}", goals
),
378 GoalData
::Not(ref g
) => write
!(fmt
, "not {{ {:?} }}", g
),
379 GoalData
::EqGoal(ref wc
) => write
!(fmt
, "{:?}", wc
),
380 GoalData
::SubtypeGoal(ref wc
) => write
!(fmt
, "{:?}", wc
),
381 GoalData
::DomainGoal(ref wc
) => write
!(fmt
, "{:?}", wc
),
382 GoalData
::CannotProve
=> write
!(fmt
, r
"¯\_(ツ)_/¯"),
387 /// Helper struct for showing debug output for `Goals`.
388 pub struct GoalsDebug
<'a
, I
: Interner
> {
393 impl<'a
, I
: Interner
> Debug
for GoalsDebug
<'a
, I
> {
394 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
396 for (goal
, index
) in self.goals
.iter(self.interner
).zip(0..) {
400 write
!(fmt
, "{:?}", goal
)?
;
407 impl<I
: Interner
> Goals
<I
> {
408 /// Show debug output for `Goals`.
409 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> GoalsDebug
<'a
, I
> {
417 /// Helper struct for showing debug output for `GenericArgData`.
418 pub struct GenericArgDataInnerDebug
<'a
, I
: Interner
>(&'a GenericArgData
<I
>);
420 impl<'a
, I
: Interner
> Debug
for GenericArgDataInnerDebug
<'a
, I
> {
421 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
423 GenericArgData
::Ty(n
) => write
!(fmt
, "{:?}", n
),
424 GenericArgData
::Lifetime(n
) => write
!(fmt
, "{:?}", n
),
425 GenericArgData
::Const(n
) => write
!(fmt
, "{:?}", n
),
430 impl<I
: Interner
> GenericArgData
<I
> {
431 /// Helper method for debugging `GenericArgData`.
432 pub fn inner_debug(&self) -> GenericArgDataInnerDebug
<'_
, I
> {
433 GenericArgDataInnerDebug(self)
437 /// Helper struct for showing debug output for program clause implications.
438 pub struct ProgramClauseImplicationDebug
<'a
, I
: Interner
> {
439 pci
: &'a ProgramClauseImplication
<I
>,
443 impl<'a
, I
: Interner
> Debug
for ProgramClauseImplicationDebug
<'a
, I
> {
444 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
445 let ProgramClauseImplicationDebug { pci, interner }
= self;
446 write
!(fmt
, "{:?}", pci
.consequence
)?
;
448 let conditions
= pci
.conditions
.as_slice(interner
);
450 let conds
= conditions
.len();
455 write
!(fmt
, " :- ")?
;
456 for cond
in &conditions
[..conds
- 1] {
457 write
!(fmt
, "{:?}, ", cond
)?
;
459 write
!(fmt
, "{:?}", conditions
[conds
- 1])
463 impl<I
: Interner
> ProgramClauseImplication
<I
> {
464 /// Show debug output for the program clause implication.
465 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> ProgramClauseImplicationDebug
<'a
, I
> {
466 ProgramClauseImplicationDebug
{
473 /// Helper struct for showing debug output for application types.
474 pub struct TyKindDebug
<'a
, I
: Interner
> {
479 impl<'a
, I
: Interner
> Debug
for TyKindDebug
<'a
, I
> {
480 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
481 let interner
= self.interner
;
483 TyKind
::BoundVar(db
) => write
!(fmt
, "{:?}", db
),
484 TyKind
::Dyn(clauses
) => write
!(fmt
, "{:?}", clauses
),
485 TyKind
::InferenceVar(var
, TyVariableKind
::General
) => write
!(fmt
, "{:?}", var
),
486 TyKind
::InferenceVar(var
, TyVariableKind
::Integer
) => write
!(fmt
, "{:?}i", var
),
487 TyKind
::InferenceVar(var
, TyVariableKind
::Float
) => write
!(fmt
, "{:?}f", var
),
488 TyKind
::Alias(alias
) => write
!(fmt
, "{:?}", alias
),
489 TyKind
::Placeholder(index
) => write
!(fmt
, "{:?}", index
),
490 TyKind
::Function(function
) => write
!(fmt
, "{:?}", function
),
491 TyKind
::Adt(id
, substitution
) => {
492 write
!(fmt
, "{:?}{:?}", id
, substitution
.with_angle(interner
))
494 TyKind
::AssociatedType(assoc_ty
, substitution
) => {
495 write
!(fmt
, "{:?}{:?}", assoc_ty
, substitution
.with_angle(interner
))
497 TyKind
::Scalar(scalar
) => write
!(fmt
, "{:?}", scalar
),
498 TyKind
::Str
=> write
!(fmt
, "Str"),
499 TyKind
::Tuple(arity
, substitution
) => {
500 write
!(fmt
, "{:?}{:?}", arity
, substitution
.with_angle(interner
))
502 TyKind
::OpaqueType(opaque_ty
, substitution
) => write
!(
506 substitution
.with_angle(interner
)
508 TyKind
::Slice(ty
) => write
!(fmt
, "[{:?}]", ty
),
509 TyKind
::FnDef(fn_def
, substitution
) => {
510 write
!(fmt
, "{:?}{:?}", fn_def
, substitution
.with_angle(interner
))
512 TyKind
::Ref(mutability
, lifetime
, ty
) => match mutability
{
513 Mutability
::Mut
=> write
!(fmt
, "(&{:?} mut {:?})", lifetime
, ty
),
514 Mutability
::Not
=> write
!(fmt
, "(&{:?} {:?})", lifetime
, ty
),
516 TyKind
::Raw(mutability
, ty
) => match mutability
{
517 Mutability
::Mut
=> write
!(fmt
, "(*mut {:?})", ty
),
518 Mutability
::Not
=> write
!(fmt
, "(*const {:?})", ty
),
520 TyKind
::Never
=> write
!(fmt
, "Never"),
521 TyKind
::Array(ty
, const_
) => write
!(fmt
, "[{:?}; {:?}]", ty
, const_
),
522 TyKind
::Closure(id
, substitution
) => write
!(
524 "{{closure:{:?}}}{:?}",
526 substitution
.with_angle(interner
)
528 TyKind
::Generator(generator
, substitution
) => write
!(
532 substitution
.with_angle(interner
)
534 TyKind
::GeneratorWitness(witness
, substitution
) => {
535 write
!(fmt
, "{:?}{:?}", witness
, substitution
.with_angle(interner
))
537 TyKind
::Foreign(foreign_ty
) => write
!(fmt
, "{:?}", foreign_ty
,),
538 TyKind
::Error
=> write
!(fmt
, "{{error}}"),
543 impl<I
: Interner
> TyKind
<I
> {
544 /// Show debug output for the application type.
545 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> TyKindDebug
<'a
, I
> {
546 TyKindDebug { ty: self, interner }
550 /// Helper struct for showing debug output for substitutions.
551 pub struct SubstitutionDebug
<'a
, I
: Interner
> {
552 substitution
: &'a Substitution
<I
>,
556 impl<'a
, I
: Interner
> Debug
for SubstitutionDebug
<'a
, I
> {
557 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
558 let SubstitutionDebug
{
562 let mut first
= true;
566 for (index
, value
) in substitution
.iter(interner
).enumerate() {
573 write
!(fmt
, "?{} := {:?}", index
, value
)?
;
582 impl<I
: Interner
> Substitution
<I
> {
583 /// Show debug output for the substitution.
584 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> SubstitutionDebug
<'a
, I
> {
592 impl Debug
for PlaceholderIndex
{
593 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
594 let PlaceholderIndex { ui, idx }
= self;
595 write
!(fmt
, "!{}_{}", ui
.counter
, idx
)
599 impl<I
: Interner
> TraitRef
<I
> {
600 /// Returns a "Debuggable" type that prints like `P0 as Trait<P1..>`.
601 pub fn with_as(&self) -> impl std
::fmt
::Debug
+ '_
{
608 /// Returns a "Debuggable" type that prints like `P0: Trait<P1..>`.
609 pub fn with_colon(&self) -> impl std
::fmt
::Debug
+ '_
{
617 impl<I
: Interner
> Debug
for TraitRef
<I
> {
618 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
619 Debug
::fmt(&self.with_as(), fmt
)
623 /// Trait ref with associated separator used for debug output.
624 pub struct SeparatorTraitRef
<'me
, I
: Interner
> {
625 /// The `TraitRef` itself.
626 pub trait_ref
: &'me TraitRef
<I
>,
628 /// The separator used for displaying the `TraitRef`.
629 pub separator
: &'me
str,
632 /// Helper struct for showing debug output for the `SeperatorTraitRef`.
633 pub struct SeparatorTraitRefDebug
<'a
, 'me
, I
: Interner
> {
634 separator_trait_ref
: &'a SeparatorTraitRef
<'me
, I
>,
638 impl<'a
, 'me
, I
: Interner
> Debug
for SeparatorTraitRefDebug
<'a
, 'me
, I
> {
639 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
640 let SeparatorTraitRefDebug
{
644 let parameters
= separator_trait_ref
652 separator_trait_ref
.separator
,
653 separator_trait_ref
.trait_ref
.trait_id
,
654 Angle(¶meters
[1..])
659 impl<'me
, I
: Interner
> SeparatorTraitRef
<'me
, I
> {
660 /// Show debug output for the `SeperatorTraitRef`.
661 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> SeparatorTraitRefDebug
<'a
, 'me
, I
> {
662 SeparatorTraitRefDebug
{
663 separator_trait_ref
: self,
669 impl<I
: Interner
> Debug
for LifetimeOutlives
<I
> {
670 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
671 write
!(fmt
, "{:?}: {:?}", self.a
, self.b
)
675 impl<I
: Interner
> Debug
for TypeOutlives
<I
> {
676 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
677 write
!(fmt
, "{:?}: {:?}", self.ty
, self.lifetime
)
681 /// Helper struct for showing debug output for projection types.
682 pub struct ProjectionTyDebug
<'a
, I
: Interner
> {
683 projection_ty
: &'a ProjectionTy
<I
>,
687 impl<'a
, I
: Interner
> Debug
for ProjectionTyDebug
<'a
, I
> {
688 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
689 let ProjectionTyDebug
{
696 projection_ty
.associated_ty_id
,
697 projection_ty
.substitution
.with_angle(interner
)
702 impl<I
: Interner
> ProjectionTy
<I
> {
703 /// Show debug output for the projection type.
704 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> ProjectionTyDebug
<'a
, I
> {
712 /// Helper struct for showing debug output for opaque types.
713 pub struct OpaqueTyDebug
<'a
, I
: Interner
> {
714 opaque_ty
: &'a OpaqueTy
<I
>,
718 impl<'a
, I
: Interner
> Debug
for OpaqueTyDebug
<'a
, I
> {
719 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
727 opaque_ty
.opaque_ty_id
,
728 opaque_ty
.substitution
.with_angle(interner
)
733 impl<I
: Interner
> OpaqueTy
<I
> {
734 /// Show debug output for the opaque type.
735 pub fn debug
<'a
>(&'a
self, interner
: &'a I
) -> OpaqueTyDebug
<'a
, I
> {
743 /// Wraps debug output in angle brackets (`<>`).
744 pub struct Angle
<'a
, T
>(pub &'a
[T
]);
746 impl<'a
, T
: Debug
> Debug
for Angle
<'a
, T
> {
747 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
748 if !self.0.is_empty
() {
750 for (index
, elem
) in self.0.iter
().enumerate() {
752 write
!(fmt
, ", {:?}", elem
)?
;
754 write
!(fmt
, "{:?}", elem
)?
;
763 impl<I
: Interner
> Debug
for Normalize
<I
> {
764 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
765 write
!(fmt
, "Normalize({:?} -> {:?})", self.alias
, self.ty
)
769 impl<I
: Interner
> Debug
for AliasEq
<I
> {
770 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
771 write
!(fmt
, "AliasEq({:?} = {:?})", self.alias
, self.ty
)
775 impl<I
: Interner
> Debug
for WhereClause
<I
> {
776 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
778 WhereClause
::Implemented(tr
) => write
!(fmt
, "Implemented({:?})", tr
.with_colon()),
779 WhereClause
::AliasEq(a
) => write
!(fmt
, "{:?}", a
),
780 WhereClause
::LifetimeOutlives(l_o
) => write
!(fmt
, "{:?}", l_o
),
781 WhereClause
::TypeOutlives(t_o
) => write
!(fmt
, "{:?}", t_o
),
786 impl<I
: Interner
> Debug
for FromEnv
<I
> {
787 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
789 FromEnv
::Trait(t
) => write
!(fmt
, "FromEnv({:?})", t
.with_colon()),
790 FromEnv
::Ty(t
) => write
!(fmt
, "FromEnv({:?})", t
),
795 impl<I
: Interner
> Debug
for WellFormed
<I
> {
796 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
798 WellFormed
::Trait(t
) => write
!(fmt
, "WellFormed({:?})", t
.with_colon()),
799 WellFormed
::Ty(t
) => write
!(fmt
, "WellFormed({:?})", t
),
804 impl<I
: Interner
> Debug
for DomainGoal
<I
> {
805 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
807 DomainGoal
::Holds(n
) => write
!(fmt
, "{:?}", n
),
808 DomainGoal
::WellFormed(n
) => write
!(fmt
, "{:?}", n
),
809 DomainGoal
::FromEnv(n
) => write
!(fmt
, "{:?}", n
),
810 DomainGoal
::Normalize(n
) => write
!(fmt
, "{:?}", n
),
811 DomainGoal
::IsLocal(n
) => write
!(fmt
, "IsLocal({:?})", n
),
812 DomainGoal
::IsUpstream(n
) => write
!(fmt
, "IsUpstream({:?})", n
),
813 DomainGoal
::IsFullyVisible(n
) => write
!(fmt
, "IsFullyVisible({:?})", n
),
814 DomainGoal
::LocalImplAllowed(tr
) => {
815 write
!(fmt
, "LocalImplAllowed({:?})", tr
.with_colon(),)
817 DomainGoal
::Compatible
=> write
!(fmt
, "Compatible"),
818 DomainGoal
::DownstreamType(n
) => write
!(fmt
, "DownstreamType({:?})", n
),
819 DomainGoal
::Reveal
=> write
!(fmt
, "Reveal"),
820 DomainGoal
::ObjectSafe(n
) => write
!(fmt
, "ObjectSafe({:?})", n
),
825 impl<I
: Interner
> Debug
for EqGoal
<I
> {
826 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
827 write
!(fmt
, "({:?} = {:?})", self.a
, self.b
)
831 impl<I
: Interner
> Debug
for SubtypeGoal
<I
> {
832 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
833 write
!(fmt
, "({:?} <: {:?})", self.a
, self.b
)
837 impl<T
: HasInterner
+ Debug
> Debug
for Binders
<T
> {
838 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
843 write
!(fmt
, "for{:?} ", binders
.debug())?
;
844 Debug
::fmt(value
, fmt
)
848 impl<I
: Interner
> Debug
for ProgramClauseData
<I
> {
849 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
850 write
!(fmt
, "{:?}", self.0)
854 impl<I
: Interner
> Debug
for Environment
<I
> {
855 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
856 write
!(fmt
, "Env({:?})", self.clauses
)
860 impl<I
: Interner
> Debug
for CanonicalVarKinds
<I
> {
861 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
862 I
::debug_canonical_var_kinds(self, fmt
)
863 .unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))
867 impl<T
: HasInterner
+ Display
> Canonical
<T
> {
868 /// Display the canonicalized item.
869 pub fn display
<'a
>(&'a
self, interner
: &'a T
::Interner
) -> CanonicalDisplay
<'a
, T
> {
877 /// Helper struct for displaying canonicalized items.
878 pub struct CanonicalDisplay
<'a
, T
: HasInterner
> {
879 canonical
: &'a Canonical
<T
>,
880 interner
: &'a T
::Interner
,
883 impl<'a
, T
: HasInterner
+ Display
> Display
for CanonicalDisplay
<'a
, T
> {
884 fn fmt(&self, f
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
885 let Canonical { binders, value }
= self.canonical
;
886 let interner
= self.interner
;
887 let binders
= binders
.as_slice(interner
);
888 if binders
.is_empty() {
889 // Ordinarily, we try to print all binder levels, if they
890 // are empty, but we can skip in this *particular* case
891 // because we know that `Canonical` terms are never
892 // supposed to contain free variables. In other words,
893 // all "bound variables" that appear inside the canonical
894 // value must reference values that appear in `binders`.
895 write
!(f
, "{}", value
)?
;
899 for (i
, pk
) in binders
.iter().enumerate() {
903 write
!(f
, "?{}", pk
.skip_kind())?
;
906 write
!(f
, "> {{ {} }}", value
)?
;
913 impl<I
: Interner
> Debug
for GenericArgData
<I
> {
914 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
916 GenericArgData
::Ty(t
) => write
!(fmt
, "Ty({:?})", t
),
917 GenericArgData
::Lifetime(l
) => write
!(fmt
, "Lifetime({:?})", l
),
918 GenericArgData
::Const(c
) => write
!(fmt
, "Const({:?})", c
),
923 impl<I
: Interner
> Debug
for VariableKind
<I
> {
924 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
926 VariableKind
::Ty(TyVariableKind
::General
) => write
!(fmt
, "type"),
927 VariableKind
::Ty(TyVariableKind
::Integer
) => write
!(fmt
, "integer type"),
928 VariableKind
::Ty(TyVariableKind
::Float
) => write
!(fmt
, "float type"),
929 VariableKind
::Lifetime
=> write
!(fmt
, "lifetime"),
930 VariableKind
::Const(ty
) => write
!(fmt
, "const: {:?}", ty
),
935 impl<I
: Interner
, T
: Debug
> Debug
for WithKind
<I
, T
> {
936 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
937 let value
= self.skip_kind();
939 VariableKind
::Ty(TyVariableKind
::General
) => write
!(fmt
, "{:?} with kind type", value
),
940 VariableKind
::Ty(TyVariableKind
::Integer
) => {
941 write
!(fmt
, "{:?} with kind integer type", value
)
943 VariableKind
::Ty(TyVariableKind
::Float
) => {
944 write
!(fmt
, "{:?} with kind float type", value
)
946 VariableKind
::Lifetime
=> write
!(fmt
, "{:?} with kind lifetime", value
),
947 VariableKind
::Const(ty
) => write
!(fmt
, "{:?} with kind {:?}", value
, ty
),
952 impl<I
: Interner
> Debug
for Constraint
<I
> {
953 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
955 Constraint
::LifetimeOutlives(a
, b
) => write
!(fmt
, "{:?}: {:?}", a
, b
),
956 Constraint
::TypeOutlives(ty
, lifetime
) => write
!(fmt
, "{:?}: {:?}", ty
, lifetime
),
961 impl<I
: Interner
> Display
for ConstrainedSubst
<I
> {
962 fn fmt(&self, f
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
963 let ConstrainedSubst { subst, constraints }
= self;
967 "substitution {}, lifetime constraints {:?}",
973 impl<I
: Interner
> Substitution
<I
> {
974 /// Displays the substitution in the form `< P0, .. Pn >`, or (if
975 /// the substitution is empty) as an empty string.
976 pub fn with_angle(&self, interner
: &I
) -> Angle
<'_
, GenericArg
<I
>> {
977 Angle(self.as_slice(interner
))
981 impl<I
: Interner
> Debug
for Substitution
<I
> {
982 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
983 Display
::fmt(self, fmt
)
987 impl<I
: Interner
> Debug
for Variances
<I
> {
988 fn fmt(&self, fmt
: &mut Formatter
<'_
>) -> Result
<(), Error
> {
989 I
::debug_variances(self, fmt
).unwrap_or_else(|| write
!(fmt
, "{:?}", self.interned
))