Skip to content

Commit ded9342

Browse files
committed
add more coherence tests
1 parent 18295ee commit ded9342

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

tests/coherence.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(non_snake_case)] // we embed type names into the names for our test functions
2+
13
use formality::test_program_ok;
24
use formality_macros::test;
35

@@ -38,7 +40,6 @@ fn test_u32_u32_impls() {
3840
}
3941

4042
#[test]
41-
#[allow(non_snake_case)]
4243
fn test_u32_T_impls() {
4344
expect_test::expect![[r#"
4445
Err(
@@ -57,7 +58,6 @@ fn test_u32_T_impls() {
5758
}
5859

5960
#[test]
60-
#[allow(non_snake_case)]
6161
fn test_u32_T_where_T_Not_impls() {
6262
expect_test::expect![[r#"
6363
Ok(
@@ -78,7 +78,6 @@ fn test_u32_T_where_T_Not_impls() {
7878
}
7979

8080
#[test]
81-
#[allow(non_snake_case)]
8281
fn test_u32_T_where_T_Is_impls() {
8382
expect_test::expect![[r#"
8483
Err(
@@ -121,8 +120,12 @@ fn test_u32_not_u32_impls() {
121120
}
122121

123122
#[test]
124-
#[allow(non_snake_case)]
125123
fn test_T_where_Foo_not_u32_impls() {
124+
// Test positive impl that has a where-clause which checks for itself,
125+
// i.e., `T: Foo where T: Foo`. This `T: Foo` where-clause isn't harmful
126+
// in the coinductive interpretation of trait matching, it actually
127+
// doesn't change the meaning of the impl at all. However, this formulation
128+
// was erroneously accepted by an earlier variant of negative impls.
126129
expect_test::expect![[r#"
127130
Err(
128131
Error {
@@ -143,8 +146,7 @@ fn test_T_where_Foo_not_u32_impls() {
143146
}
144147

145148
#[test]
146-
#[allow(non_snake_case)]
147-
fn test_non_local() {
149+
fn test_foo_crate_cannot_assume_CoreStruct_does_not_impl_CoreTrait() {
148150
expect_test::expect![[r#"
149151
Err(
150152
"impls may overlap: `impl <ty> FooTrait < > for ^ty0_0 where [^ty0_0 : CoreTrait < >] { }` vs `impl <> FooTrait < > for (rigid (adt CoreStruct)) where [] { }`",
@@ -166,7 +168,7 @@ fn test_non_local() {
166168
}
167169

168170
#[test]
169-
fn test_orphan() {
171+
fn test_orphan_basic() {
170172
expect_test::expect![[r#"
171173
Err(
172174
Error {
@@ -187,3 +189,29 @@ fn test_orphan() {
187189
]",
188190
));
189191
}
192+
193+
#[test]
194+
fn test_neg_CoreTrait_for_CoreStruct_implies_no_overlap() {
195+
// Variant of test_foo_crate_cannot_assume_CoreStruct_does_not_impl_CoreTrait
196+
// where there is a negative impl, so it is accepted.
197+
198+
expect_test::expect![[r#"
199+
Ok(
200+
(),
201+
)
202+
"#]]
203+
.assert_debug_eq(&test_program_ok(
204+
"[
205+
crate core {
206+
trait CoreTrait<> where [] {}
207+
struct CoreStruct<> where [] {}
208+
impl<> !CoreTrait<> for CoreStruct<> where [] {}
209+
},
210+
crate foo {
211+
trait FooTrait<> where [] {}
212+
impl<ty T> FooTrait<> for T where [T: CoreTrait<>] {}
213+
impl<> FooTrait<> for CoreStruct<> where [] {}
214+
}
215+
]",
216+
));
217+
}

0 commit comments

Comments
 (0)