1
+ #![ allow( non_snake_case) ] // we embed type names into the names for our test functions
2
+
1
3
use formality:: test_program_ok;
2
4
use formality_macros:: test;
3
5
@@ -38,7 +40,6 @@ fn test_u32_u32_impls() {
38
40
}
39
41
40
42
#[ test]
41
- #[ allow( non_snake_case) ]
42
43
fn test_u32_T_impls ( ) {
43
44
expect_test:: expect![ [ r#"
44
45
Err(
@@ -57,7 +58,6 @@ fn test_u32_T_impls() {
57
58
}
58
59
59
60
#[ test]
60
- #[ allow( non_snake_case) ]
61
61
fn test_u32_T_where_T_Not_impls ( ) {
62
62
expect_test:: expect![ [ r#"
63
63
Ok(
@@ -78,7 +78,6 @@ fn test_u32_T_where_T_Not_impls() {
78
78
}
79
79
80
80
#[ test]
81
- #[ allow( non_snake_case) ]
82
81
fn test_u32_T_where_T_Is_impls ( ) {
83
82
expect_test:: expect![ [ r#"
84
83
Err(
@@ -121,8 +120,12 @@ fn test_u32_not_u32_impls() {
121
120
}
122
121
123
122
#[ test]
124
- #[ allow( non_snake_case) ]
125
123
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.
126
129
expect_test:: expect![ [ r#"
127
130
Err(
128
131
Error {
@@ -143,8 +146,7 @@ fn test_T_where_Foo_not_u32_impls() {
143
146
}
144
147
145
148
#[ test]
146
- #[ allow( non_snake_case) ]
147
- fn test_non_local ( ) {
149
+ fn test_foo_crate_cannot_assume_CoreStruct_does_not_impl_CoreTrait ( ) {
148
150
expect_test:: expect![ [ r#"
149
151
Err(
150
152
"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() {
166
168
}
167
169
168
170
#[ test]
169
- fn test_orphan ( ) {
171
+ fn test_orphan_basic ( ) {
170
172
expect_test:: expect![ [ r#"
171
173
Err(
172
174
Error {
@@ -187,3 +189,29 @@ fn test_orphan() {
187
189
]" ,
188
190
) ) ;
189
191
}
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