Skip to content

Commit d415364

Browse files
committed
Extract Debug for GoalData implementation.
1 parent 1ac0d00 commit d415364

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

chalk-integration/src/program.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use chalk_ir::debug::Angle;
44
use chalk_ir::interner::ChalkIr;
55
use chalk_ir::tls;
66
use chalk_ir::{
7-
debug::SeparatorTraitRef, AliasTy, ApplicationTy, AssocTypeId, Goal, GoalData, Goals, ImplId,
8-
Lifetime, Parameter, ParameterKind, ProgramClause, ProgramClauseImplication, StructId,
9-
Substitution, TraitId, Ty, TyData, TypeName,
7+
debug::SeparatorTraitRef, AliasTy, ApplicationTy, AssocTypeId, Goal, Goals, ImplId, Lifetime,
8+
Parameter, ParameterKind, ProgramClause, ProgramClauseImplication, StructId, Substitution,
9+
TraitId, Ty, TyData, TypeName,
1010
};
1111
use chalk_rust_ir::{
1212
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType, StructDatum,
@@ -155,27 +155,8 @@ impl tls::DebugContext for Program {
155155
fmt: &mut fmt::Formatter<'_>,
156156
) -> Result<(), fmt::Error> {
157157
let interner = self.interner();
158-
match goal.data(interner) {
159-
GoalData::Quantified(qkind, ref subgoal) => {
160-
write!(fmt, "{:?}<", qkind)?;
161-
for (index, binder) in subgoal.binders.iter().enumerate() {
162-
if index > 0 {
163-
write!(fmt, ", ")?;
164-
}
165-
match *binder {
166-
ParameterKind::Ty(()) => write!(fmt, "type")?,
167-
ParameterKind::Lifetime(()) => write!(fmt, "lifetime")?,
168-
}
169-
}
170-
write!(fmt, "> {{ {:?} }}", subgoal.value)
171-
}
172-
GoalData::Implies(ref wc, ref g) => write!(fmt, "if ({:?}) {{ {:?} }}", wc, g),
173-
GoalData::All(ref goals) => write!(fmt, "all{:?}", goals),
174-
GoalData::Not(ref g) => write!(fmt, "not {{ {:?} }}", g),
175-
GoalData::EqGoal(ref wc) => write!(fmt, "{:?}", wc),
176-
GoalData::DomainGoal(ref wc) => write!(fmt, "{:?}", wc),
177-
GoalData::CannotProve(()) => write!(fmt, r"¯\_(ツ)_/¯"),
178-
}
158+
write!(fmt, "{:?}", goal.data(interner))?;
159+
Ok(())
179160
}
180161

181162
fn debug_goals(

chalk-ir/src/debug.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,32 @@ impl<I: Interner> Debug for LifetimeData<I> {
169169
}
170170
}
171171

172+
impl<I: Interner> Debug for GoalData<I> {
173+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
174+
match self {
175+
GoalData::Quantified(qkind, ref subgoal) => {
176+
write!(fmt, "{:?}<", qkind)?;
177+
for (index, binder) in subgoal.binders.iter().enumerate() {
178+
if index > 0 {
179+
write!(fmt, ", ")?;
180+
}
181+
match *binder {
182+
ParameterKind::Ty(()) => write!(fmt, "type")?,
183+
ParameterKind::Lifetime(()) => write!(fmt, "lifetime")?,
184+
}
185+
}
186+
write!(fmt, "> {{ {:?} }}", subgoal.value)
187+
}
188+
GoalData::Implies(ref wc, ref g) => write!(fmt, "if ({:?}) {{ {:?} }}", wc, g),
189+
GoalData::All(ref goals) => write!(fmt, "all{:?}", goals),
190+
GoalData::Not(ref g) => write!(fmt, "not {{ {:?} }}", g),
191+
GoalData::EqGoal(ref wc) => write!(fmt, "{:?}", wc),
192+
GoalData::DomainGoal(ref wc) => write!(fmt, "{:?}", wc),
193+
GoalData::CannotProve(()) => write!(fmt, r"¯\_(ツ)_/¯"),
194+
}
195+
}
196+
}
197+
172198
impl Debug for PlaceholderIndex {
173199
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
174200
let PlaceholderIndex { ui, idx } = self;

chalk-ir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ where
11791179
}
11801180
}
11811181

1182-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)]
1182+
#[derive(Clone, PartialEq, Eq, Hash, Fold, HasInterner)]
11831183
/// A general goal; this is the full range of questions you can pose to Chalk.
11841184
pub enum GoalData<I: Interner> {
11851185
/// Introduces a binding at depth 0, shifting other bindings up

0 commit comments

Comments
 (0)