File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
crates/formality-check/src Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,15 @@ impl Check<'_> {
60
60
return Ok ( ( ) ) ;
61
61
}
62
62
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
+
63
72
bail ! ( "impls may overlap: `{impl_a:?}` vs `{impl_b:?}`" )
64
73
}
65
74
}
Original file line number Diff line number Diff line change @@ -55,3 +55,44 @@ fn test_u32_T_impls() {
55
55
]" ,
56
56
) ) ;
57
57
}
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
+ }
You can’t perform that action at this time.
0 commit comments