Skip to content

Commit cde1c34

Browse files
committed
Use all_sub
1 parent e207b38 commit cde1c34

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

crates/formality-check/src/mini_rust_check.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -410,24 +410,28 @@ impl Check<'_> {
410410
bail!("The length of ValueExpression::Tuple does not match the type of the ADT declared")
411411
}
412412

413-
let expression_ty_pair = zip(value_expressions, struct_field_tys);
413+
let mut value_tys: Vec<Ty> = Vec::new();
414414

415-
// FIXME: we only support const in value expression of struct for now, we can add support
416-
// more in future.
417-
418-
for (value_expression, declared_ty) in expression_ty_pair {
415+
for value_expression in value_expressions {
416+
// FIXME: we only support const in value expression of struct for now, we can add support
417+
// more in future.
419418
let Constant(_) = value_expression else {
420419
bail!("Only Constant is supported in ValueExpression::Struct for now.")
421420
};
422-
let ty = self.check_value(typeck_env, fn_assumptions, value_expression)?;
423-
424-
// Make sure the type matches the declared adt.
425-
if ty != declared_ty {
426-
bail!(
427-
"The type in ValueExpression::Tuple does not match the struct declared"
428-
)
429-
}
421+
value_tys.push(self.check_value(
422+
typeck_env,
423+
fn_assumptions,
424+
value_expression,
425+
)?);
430426
}
427+
428+
// Make sure all the types supplied are the subtype of declared types.
429+
self.prove_goal(
430+
&typeck_env.env,
431+
&fn_assumptions,
432+
Wcs::all_sub(value_tys, struct_field_tys),
433+
)?;
434+
431435
Ok(ty.clone())
432436
}
433437
}

src/test/mir_fn_bodies.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,18 @@ fn test_struct_wrong_type_in_initialisation() {
889889
}
890890
]
891891
[]
892-
expect_test::expect!["The type in ValueExpression::Tuple does not match the struct declared"]
892+
expect_test::expect![[r#"
893+
judgment `prove { goal: {bool <: u32}, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] }, decls: decls(222, [], [], [], [], [], [adt Dummy { struct { value : u32 } }], {}, {Dummy}) }` failed at the following rule(s):
894+
failed at (src/file.rs:LL:CC) because
895+
judgment `prove_wc_list { goal: {bool <: u32}, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }` failed at the following rule(s):
896+
the rule "some" failed at step #0 (src/file.rs:LL:CC) because
897+
judgment `prove_wc { goal: bool <: u32, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }` failed at the following rule(s):
898+
the rule "subtype" failed at step #0 (src/file.rs:LL:CC) because
899+
judgment `prove_sub { a: bool, b: u32, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }` failed at the following rule(s):
900+
the rule "normalize-l" failed at step #0 (src/file.rs:LL:CC) because
901+
judgment had no applicable rules: `prove_normalize { p: bool, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }`
902+
the rule "normalize-r" failed at step #0 (src/file.rs:LL:CC) because
903+
judgment had no applicable rules: `prove_normalize { p: u32, assumptions: {}, env: Env { variables: [], bias: Soundness, pending: [] } }`"#]]
893904
)
894905
}
895906

0 commit comments

Comments
 (0)