-
Notifications
You must be signed in to change notification settings - Fork 744
/
test_self.rs
101 lines (88 loc) · 2.06 KB
/
test_self.rs
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
use serde::{Deserialize, Serialize};
#[test]
fn test_self() {
macro_rules! mac {
($($tt:tt)*) => {
$($tt)*
};
}
pub trait Trait {
type Assoc;
}
#[derive(Deserialize, Serialize)]
pub struct Generics<T: Trait<Assoc = Self>>
where
Self: Trait<Assoc = Self>,
<Self as Trait>::Assoc: Sized,
mac!(Self): Trait<Assoc = mac!(Self)>,
{
_f: T,
}
impl<T: Trait<Assoc = Self>> Trait for Generics<T> {
type Assoc = Self;
}
#[derive(Deserialize, Serialize)]
pub struct Struct {
_f1: Box<Self>,
_f2: Box<<Self as Trait>::Assoc>,
_f3: Box<mac!(Self)>,
_f4: [(); Self::ASSOC],
_f5: [(); Self::assoc()],
_f6: [(); mac!(Self::assoc())],
}
impl Struct {
const ASSOC: usize = 1;
const fn assoc() -> usize {
0
}
}
impl Trait for Struct {
type Assoc = Self;
}
#[derive(Deserialize, Serialize)]
struct Tuple(
Box<Self>,
Box<<Self as Trait>::Assoc>,
Box<mac!(Self)>,
[(); Self::ASSOC],
[(); Self::assoc()],
[(); mac!(Self::assoc())],
);
impl Tuple {
const ASSOC: usize = 1;
const fn assoc() -> usize {
0
}
}
impl Trait for Tuple {
type Assoc = Self;
}
#[derive(Deserialize, Serialize)]
enum Enum {
Struct {
_f1: Box<Self>,
_f2: Box<<Self as Trait>::Assoc>,
_f3: Box<mac!(Self)>,
_f4: [(); Self::ASSOC],
_f5: [(); Self::assoc()],
_f6: [(); mac!(Self::assoc())],
},
Tuple(
Box<Self>,
Box<<Self as Trait>::Assoc>,
Box<mac!(Self)>,
[(); Self::ASSOC],
[(); Self::assoc()],
[(); mac!(Self::assoc())],
),
}
impl Enum {
const ASSOC: usize = 1;
const fn assoc() -> usize {
0
}
}
impl Trait for Enum {
type Assoc = Self;
}
}