[ty] Stop testing the (brittle) constraint set display implementation (#21743)
The `Display` implementation for constraint sets is brittle, and deserves a rethink. But later! It's perfectly fine for printf debugging; we just shouldn't be writing mdtests that depend on any particular rendering details. Most of these tests can be replaced with an equivalence check that actually validates that the _behavior_ of two constraint sets are identical.
This commit is contained in:
@@ -418,6 +418,7 @@ impl<'db> ConstraintSet<'db> {
|
||||
Self::constrain_typevar(db, typevar, lower, upper, TypeRelation::Assignability)
|
||||
}
|
||||
|
||||
#[expect(dead_code)] // Keep this around for debugging purposes
|
||||
pub(crate) fn display(self, db: &'db dyn Db) -> impl Display {
|
||||
self.node.simplify_for_display(db).display(db)
|
||||
}
|
||||
|
||||
@@ -2213,10 +2213,8 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
KnownInstanceType::ConstraintSet(tracked_set) => {
|
||||
let constraints = tracked_set.constraints(self.db);
|
||||
f.with_type(ty).write_str("ty_extensions.ConstraintSet")?;
|
||||
write!(f, "[{}]", constraints.display(self.db))
|
||||
KnownInstanceType::ConstraintSet(_) => {
|
||||
f.with_type(ty).write_str("ty_extensions.ConstraintSet")
|
||||
}
|
||||
KnownInstanceType::GenericContext(generic_context) => {
|
||||
f.with_type(ty).write_str("ty_extensions.GenericContext")?;
|
||||
|
||||
@@ -10573,14 +10573,19 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||
(
|
||||
Type::KnownInstance(KnownInstanceType::ConstraintSet(left)),
|
||||
Type::KnownInstance(KnownInstanceType::ConstraintSet(right)),
|
||||
) => match op {
|
||||
ast::CmpOp::Eq => Some(Ok(Type::BooleanLiteral(
|
||||
left.constraints(self.db()) == right.constraints(self.db())
|
||||
))),
|
||||
ast::CmpOp::NotEq => Some(Ok(Type::BooleanLiteral(
|
||||
left.constraints(self.db()) != right.constraints(self.db())
|
||||
))),
|
||||
_ => None,
|
||||
) => {
|
||||
let result = match op {
|
||||
ast::CmpOp::Eq => Some(
|
||||
left.constraints(self.db()).iff(self.db(), right.constraints(self.db()))
|
||||
),
|
||||
ast::CmpOp::NotEq => Some(
|
||||
left.constraints(self.db()).iff(self.db(), right.constraints(self.db())).negate(self.db())
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
result.map(|constraints| Ok(Type::KnownInstance(KnownInstanceType::ConstraintSet(
|
||||
TrackedConstraintSet::new(self.db(), constraints)
|
||||
))))
|
||||
}
|
||||
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user