iter 22-tidy.6.2: write_fn_def renders forall class constraints

This commit is contained in:
2026-05-10 04:58:01 +02:00
parent 788c9808dd
commit 51011511b4
3 changed files with 37 additions and 4 deletions
+18 -4
View File
@@ -238,9 +238,11 @@ fn write_fn_def(out: &mut String, fd: &FnDef, level: usize) {
// `Type::Fn` or a `Type::Forall` wrapping one — in the latter case
// we render the forall on the line above and then the inner fn
// signature.
let (forall_vars, fn_ty) = match &fd.ty {
Type::Forall { vars, constraints: _, body } => (Some(vars.clone()), body.as_ref()),
other => (None, other),
let (forall_vars, forall_constraints, fn_ty) = match &fd.ty {
Type::Forall { vars, constraints, body } => {
(Some(vars.clone()), constraints.clone(), body.as_ref())
}
other => (None, Vec::new(), other),
};
if let Some(vars) = &forall_vars {
@@ -252,7 +254,19 @@ fn write_fn_def(out: &mut String, fd: &FnDef, level: usize) {
}
out.push_str(v);
}
out.push_str(">\n");
out.push('>');
if !forall_constraints.is_empty() {
out.push_str(" where ");
for (i, c) in forall_constraints.iter().enumerate() {
if i > 0 {
out.push_str(", ");
}
out.push_str(&c.class);
out.push(' ');
write_type(out, &c.type_);
}
}
out.push('\n');
}
indent(out, level);
+5
View File
@@ -81,3 +81,8 @@ fn snapshot_test_22b3_default_e2e() {
fn snapshot_test_22b2_instance_present() {
check_snapshot("test_22b2_instance_present");
}
#[test]
fn snapshot_test_22b2_constraint_declared_via_superclass() {
check_snapshot("test_22b2_constraint_declared_via_superclass");
}
@@ -0,0 +1,14 @@
// module test_22b2_constraint_declared_via_superclass
class Eq a {
fn eq(x: a, x1: a) -> Bool
}
class Ord a extends Eq {
fn lt(x: a, x1: a) -> Bool
}
forall<a> where Ord a
fn uses_eq_via_ord(x: a, y: a) -> Bool {
eq(x, y)
}