diff --git a/chalk-integration/src/interner.rs b/chalk-integration/src/interner.rs index 5e5ae0f846a..3e20018b5c0 100644 --- a/chalk-integration/src/interner.rs +++ b/chalk-integration/src/interner.rs @@ -2,9 +2,9 @@ use crate::tls; use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::{ AdtId, AliasTy, AssocTypeId, CanonicalVarKind, CanonicalVarKinds, ConstData, Constraint, - FnDefId, Goals, InEnvironment, Lifetime, OpaqueTy, OpaqueTyId, ProgramClauseImplication, - ProgramClauses, ProjectionTy, QuantifiedWhereClauses, SeparatorTraitRef, Substitution, TraitId, - Ty, TyData, VariableKind, VariableKinds, + Constraints, FnDefId, Goals, InEnvironment, Lifetime, OpaqueTy, OpaqueTyId, + ProgramClauseImplication, ProgramClauses, ProjectionTy, QuantifiedWhereClauses, + SeparatorTraitRef, Substitution, TraitId, Ty, TyData, VariableKind, VariableKinds, Variances, }; use chalk_ir::{ GenericArg, GenericArgData, Goal, GoalData, LifetimeData, ProgramClause, ProgramClauseData, @@ -206,6 +206,20 @@ impl Interner for ChalkIr { tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) } + fn debug_constraints( + constraints: &Constraints, + fmt: &mut fmt::Formatter<'_>, + ) -> Option { + tls::with_current_program(|prog| Some(prog?.debug_constraints(constraints, fmt))) + } + + fn debug_variances( + variances: &Variances, + fmt: &mut fmt::Formatter<'_>, + ) -> Option { + tls::with_current_program(|prog| Some(prog?.debug_variances(variances, fmt))) + } + fn intern_ty(&self, ty: TyData) -> Arc> { Arc::new(ty) } diff --git a/chalk-integration/src/program.rs b/chalk-integration/src/program.rs index 4e5f42e2100..a3c058dd40b 100644 --- a/chalk-integration/src/program.rs +++ b/chalk-integration/src/program.rs @@ -346,6 +346,24 @@ impl tls::DebugContext for Program { let interner = self.interner(); write!(fmt, "{:?}", clauses.as_slice(interner)) } + + fn debug_constraints( + &self, + constraints: &chalk_ir::Constraints, + fmt: &mut fmt::Formatter<'_>, + ) -> Result<(), fmt::Error> { + let interner = self.interner(); + write!(fmt, "{:?}", constraints.as_slice(interner)) + } + + fn debug_variances( + &self, + variances: &chalk_ir::Variances, + fmt: &mut fmt::Formatter<'_>, + ) -> Result<(), fmt::Error> { + let interner = self.interner(); + write!(fmt, "{:?}", variances.as_slice(interner)) + } } impl UnificationDatabase for Program { diff --git a/chalk-integration/src/tls.rs b/chalk-integration/src/tls.rs index c6ab2210141..58b1da3dfa8 100644 --- a/chalk-integration/src/tls.rs +++ b/chalk-integration/src/tls.rs @@ -1,8 +1,9 @@ use crate::interner::ChalkIr; use chalk_ir::{ - debug::SeparatorTraitRef, AdtId, AliasTy, AssocTypeId, CanonicalVarKinds, FnDefId, GenericArg, - Goal, Goals, Lifetime, OpaqueTy, OpaqueTyId, ProgramClause, ProgramClauseImplication, - ProgramClauses, ProjectionTy, QuantifiedWhereClauses, Substitution, TraitId, Ty, VariableKinds, + debug::SeparatorTraitRef, AdtId, AliasTy, AssocTypeId, CanonicalVarKinds, Constraints, FnDefId, + GenericArg, Goal, Goals, Lifetime, OpaqueTy, OpaqueTyId, ProgramClause, + ProgramClauseImplication, ProgramClauses, ProjectionTy, QuantifiedWhereClauses, Substitution, + TraitId, Ty, VariableKinds, Variances, }; use std::cell::RefCell; use std::fmt; @@ -140,6 +141,18 @@ pub trait DebugContext { clauses: &QuantifiedWhereClauses, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error>; + + fn debug_constraints( + &self, + constraints: &Constraints, + fmt: &mut fmt::Formatter<'_>, + ) -> Result<(), fmt::Error>; + + fn debug_variances( + &self, + variances: &Variances, + fmt: &mut fmt::Formatter<'_>, + ) -> Result<(), fmt::Error>; } pub fn with_current_program(op: impl FnOnce(Option<&Arc>) -> R) -> R { diff --git a/chalk-ir/src/debug.rs b/chalk-ir/src/debug.rs index fb9897394e8..6998b3050cc 100644 --- a/chalk-ir/src/debug.rs +++ b/chalk-ir/src/debug.rs @@ -977,3 +977,9 @@ impl Debug for Substitution { Display::fmt(self, fmt) } } + +impl Debug for Variances { + fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { + I::debug_variances(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned)) + } +} diff --git a/chalk-ir/src/interner.rs b/chalk-ir/src/interner.rs index ad1181b55a1..2b423bf7c97 100644 --- a/chalk-ir/src/interner.rs +++ b/chalk-ir/src/interner.rs @@ -35,6 +35,7 @@ use crate::TyData; use crate::VariableKind; use crate::VariableKinds; use crate::Variance; +use crate::Variances; use crate::{Const, ConstData}; use std::fmt::{self, Debug}; use std::hash::Hash; @@ -456,6 +457,16 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { None } + /// Prints the debug representation of a Variances. + /// Returns `None` to fallback to the default debug output. + #[allow(unused_variables)] + fn debug_variances( + variances: &Variances, + fmt: &mut fmt::Formatter<'_>, + ) -> Option { + None + } + /// Create an "interned" type from `ty`. This is not normally /// invoked directly; instead, you invoke `TyKind::intern` (which /// will ultimately call this method).