Skip to content

Commit 239dd77

Browse files
committed
more coherence
1 parent 56f897f commit 239dd77

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

crates/formality-check/src/coherence.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ impl Check<'_> {
6060
return Ok(());
6161
}
6262

63+
// If we can disprove the where clauses, then they do not overlap.
64+
if let Ok(()) = self.prove_not_goal(
65+
&env,
66+
Wcs::all_eq(&trait_ref_a.parameters, &trait_ref_b.parameters),
67+
(&a.where_clauses, &b.where_clauses),
68+
) {
69+
return Ok(());
70+
}
71+
6372
bail!("impls may overlap: `{impl_a:?}` vs `{impl_b:?}`")
6473
}
6574
}

tests/coherence.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,44 @@ fn test_u32_T_impls() {
5555
]",
5656
));
5757
}
58+
59+
#[test]
60+
fn test_u32_T_where_T_Not_impls() {
61+
expect_test::expect![[r#"
62+
Ok(
63+
(),
64+
)
65+
"#]]
66+
.assert_debug_eq(&test_program_ok(
67+
"[
68+
crate Foo {
69+
trait Foo<> where [] {}
70+
impl<> Foo<> for u32 where [] {}
71+
impl<ty T> Foo<> for T where [T: Not<>] {}
72+
73+
trait Not<> where [] {}
74+
}
75+
]",
76+
));
77+
}
78+
79+
#[test]
80+
fn test_u32_T_where_T_Is_impls() {
81+
expect_test::expect![[r#"
82+
Err(
83+
"impls may overlap: `impl <> Foo < > for (rigid (scalar u32)) where [] { }` vs `impl <ty> Foo < > for ^ty0_0 where [^ty0_0 : Is < >] { }`",
84+
)
85+
"#]]
86+
.assert_debug_eq(&test_program_ok(
87+
"[
88+
crate Foo {
89+
trait Foo<> where [] {}
90+
impl<> Foo<> for u32 where [] {}
91+
impl<ty T> Foo<> for T where [T: Is<>] {}
92+
93+
trait Is<> where [] {}
94+
impl<> Is<> for u32 where [] {}
95+
}
96+
]",
97+
));
98+
}

0 commit comments

Comments
 (0)