1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use disjoint_impls::disjoint_impls;
trait Dispatch {
type Group;
}
struct GroupA;
struct GroupB;
struct SelfGroupA;
struct InnerGroupA;
struct InnerGroupB;
impl Dispatch for u8 {
type Group = GroupA;
}
impl<T> Dispatch for Vec<T> {
type Group = GroupB;
}
impl<T: Dispatch> Dispatch for [T] {
type Group = T::Group;
}
impl Dispatch for &mut u8 {
type Group = GroupA;
}
impl<T> Dispatch for &mut [T] {
type Group = GroupB;
}
disjoint_impls! {
trait Decode {
type Output;
}
impl<R: ?Sized> Decode for &mut R
where
Self: Dispatch<Group = GroupA>,
{
type Output = SelfGroupA;
}
impl<R: ?Sized> Decode for &mut R
where
Self: Dispatch<Group = GroupB>,
R: Dispatch<Group = GroupA>,
{
type Output = InnerGroupA;
}
impl<R> Decode for &mut [R]
where
Self: Dispatch<Group = GroupB>,
[R]: Dispatch<Group = GroupB>,
{
type Output = InnerGroupB;
}
}
/*
trait Decode {
type Output;
}
const _: () = {
trait Decode0<_TŠČ0: ?core::marker::Sized>: Decode {
type Output_šč;
}
impl<'_lšč0, R: ?Sized> Decode0<GroupA> for &'_lšč0 mut R
where
&'_lšč0 mut R: Dispatch<Group = GroupA>,
{
type Output_šč = SelfGroupA;
}
trait Decode00<_TŠČ0: ?core::marker::Sized>: Decode {
type Output_šč;
}
impl<'_lšč0, R: ?Sized> Decode00<GroupA> for &'_lšč0 mut R
where
&'_lšč0 mut R: Dispatch<Group = GroupB>,
R: Dispatch<Group = GroupA>,
{
type Output_šč = InnerGroupA;
}
impl<'_lšč0, R> Decode00<GroupB> for &'_lšč0 mut [R]
where
&'_lšč0 mut [R]: Dispatch<Group = GroupB>,
[R]: Dispatch<Group = GroupB>,
{
type Output_šč = InnerGroupB;
}
impl<'_lšč0, _TŠČ0: ?core::marker::Sized + '_lšč0> Decode0<GroupB>
for &'_lšč0 mut _TŠČ0
where
_TŠČ0: Dispatch,
Self: for<'_dšč> Decode00<<_TŠČ0 as Dispatch>::Group>,
{
type Output_šč = <Self as Decode00<<_TŠČ0 as Dispatch>::Group>>::Output_šč;
}
impl<'_lšč0, _TŠČ0: ?core::marker::Sized + '_lšč0> Decode
for &'_lšč0 mut _TŠČ0
where
&'_lšč0 mut _TŠČ0: Dispatch,
Self: for<'_dšč> Decode0<<&'_lšč0 mut _TŠČ0 as Dispatch>::Group>,
{
type Output = <Self as Decode0<
<&'_lšč0 mut _TŠČ0 as Dispatch>::Group,
>>::Output_šč;
}
};
*/
#[test]
fn soft_overlap() {
fn assert_decode<T: Decode<Output = SelfGroupA>>() {}
assert_decode::<&mut u8>();
fn assert_inner_decode<T: Decode<Output = InnerGroupA>>() {}
assert_inner_decode::<&mut [u8]>();
fn assert_nested_decode<T: Decode<Output = InnerGroupB>>() {}
assert_nested_decode::<&mut [Vec<u8>]>();
}