]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
b7449926 | 11 | // run-pass |
c34b1796 AL |
12 | pub trait DeclaredTrait { |
13 | type Type; | |
14 | } | |
15 | ||
16 | impl DeclaredTrait for i32 { | |
17 | type Type = i32; | |
18 | } | |
19 | ||
20 | pub trait WhereTrait { | |
21 | type Type; | |
22 | } | |
23 | ||
24 | impl WhereTrait for i32 { | |
25 | type Type = i32; | |
26 | } | |
27 | ||
28 | // Make sure we don't add a bound that just shares a name with an associated | |
29 | // type. | |
30 | pub mod module { | |
31 | pub type Type = i32; | |
32 | } | |
33 | ||
34 | #[derive(PartialEq, Debug)] | |
35 | struct PrivateStruct<T>(T); | |
36 | ||
37 | #[derive(PartialEq, Debug)] | |
38 | struct TupleStruct<A, B: DeclaredTrait, C>( | |
39 | module::Type, | |
40 | Option<module::Type>, | |
41 | A, | |
42 | PrivateStruct<A>, | |
43 | B, | |
44 | B::Type, | |
45 | Option<B::Type>, | |
46 | <B as DeclaredTrait>::Type, | |
47 | Option<<B as DeclaredTrait>::Type>, | |
48 | C, | |
49 | C::Type, | |
50 | Option<C::Type>, | |
51 | <C as WhereTrait>::Type, | |
52 | Option<<C as WhereTrait>::Type>, | |
53 | <i32 as DeclaredTrait>::Type, | |
54 | ) where C: WhereTrait; | |
55 | ||
56 | #[derive(PartialEq, Debug)] | |
57 | pub struct Struct<A, B: DeclaredTrait, C> where C: WhereTrait { | |
58 | m1: module::Type, | |
59 | m2: Option<module::Type>, | |
60 | a1: A, | |
61 | a2: PrivateStruct<A>, | |
62 | b: B, | |
63 | b1: B::Type, | |
64 | b2: Option<B::Type>, | |
65 | b3: <B as DeclaredTrait>::Type, | |
66 | b4: Option<<B as DeclaredTrait>::Type>, | |
67 | c: C, | |
68 | c1: C::Type, | |
69 | c2: Option<C::Type>, | |
70 | c3: <C as WhereTrait>::Type, | |
71 | c4: Option<<C as WhereTrait>::Type>, | |
72 | d: <i32 as DeclaredTrait>::Type, | |
73 | } | |
74 | ||
75 | #[derive(PartialEq, Debug)] | |
76 | enum Enum<A, B: DeclaredTrait, C> where C: WhereTrait { | |
77 | Unit, | |
78 | Seq( | |
79 | module::Type, | |
80 | Option<module::Type>, | |
81 | A, | |
82 | PrivateStruct<A>, | |
83 | B, | |
84 | B::Type, | |
85 | Option<B::Type>, | |
86 | <B as DeclaredTrait>::Type, | |
87 | Option<<B as DeclaredTrait>::Type>, | |
88 | C, | |
89 | C::Type, | |
90 | Option<C::Type>, | |
91 | <C as WhereTrait>::Type, | |
92 | Option<<C as WhereTrait>::Type>, | |
93 | <i32 as DeclaredTrait>::Type, | |
94 | ), | |
95 | Map { | |
96 | m1: module::Type, | |
97 | m2: Option<module::Type>, | |
98 | a1: A, | |
99 | a2: PrivateStruct<A>, | |
100 | b: B, | |
101 | b1: B::Type, | |
102 | b2: Option<B::Type>, | |
103 | b3: <B as DeclaredTrait>::Type, | |
104 | b4: Option<<B as DeclaredTrait>::Type>, | |
105 | c: C, | |
106 | c1: C::Type, | |
107 | c2: Option<C::Type>, | |
108 | c3: <C as WhereTrait>::Type, | |
109 | c4: Option<<C as WhereTrait>::Type>, | |
110 | d: <i32 as DeclaredTrait>::Type, | |
111 | }, | |
112 | } | |
113 | ||
114 | fn main() { | |
115 | let e: TupleStruct< | |
116 | i32, | |
117 | i32, | |
118 | i32, | |
119 | > = TupleStruct( | |
120 | 0, | |
121 | None, | |
122 | 0, | |
123 | PrivateStruct(0), | |
124 | 0, | |
125 | 0, | |
126 | None, | |
127 | 0, | |
128 | None, | |
129 | 0, | |
130 | 0, | |
131 | None, | |
132 | 0, | |
133 | None, | |
134 | 0, | |
135 | ); | |
136 | assert_eq!(e, e); | |
137 | ||
138 | let e: Struct< | |
139 | i32, | |
140 | i32, | |
141 | i32, | |
142 | > = Struct { | |
143 | m1: 0, | |
144 | m2: None, | |
145 | a1: 0, | |
146 | a2: PrivateStruct(0), | |
147 | b: 0, | |
148 | b1: 0, | |
149 | b2: None, | |
150 | b3: 0, | |
151 | b4: None, | |
152 | c: 0, | |
153 | c1: 0, | |
154 | c2: None, | |
155 | c3: 0, | |
156 | c4: None, | |
157 | d: 0, | |
158 | }; | |
159 | assert_eq!(e, e); | |
160 | ||
161 | let e = Enum::Unit::<i32, i32, i32>; | |
162 | assert_eq!(e, e); | |
163 | ||
164 | let e: Enum< | |
165 | i32, | |
166 | i32, | |
167 | i32, | |
168 | > = Enum::Seq( | |
169 | 0, | |
170 | None, | |
171 | 0, | |
172 | PrivateStruct(0), | |
173 | 0, | |
174 | 0, | |
175 | None, | |
176 | 0, | |
177 | None, | |
178 | 0, | |
179 | 0, | |
180 | None, | |
181 | 0, | |
182 | None, | |
183 | 0, | |
184 | ); | |
185 | assert_eq!(e, e); | |
186 | ||
187 | let e: Enum< | |
188 | i32, | |
189 | i32, | |
190 | i32, | |
191 | > = Enum::Map { | |
192 | m1: 0, | |
193 | m2: None, | |
194 | a1: 0, | |
195 | a2: PrivateStruct(0), | |
196 | b: 0, | |
197 | b1: 0, | |
198 | b2: None, | |
199 | b3: 0, | |
200 | b4: None, | |
201 | c: 0, | |
202 | c1: 0, | |
203 | c2: None, | |
204 | c3: 0, | |
205 | c4: None, | |
206 | d: 0, | |
207 | }; | |
208 | assert_eq!(e, e); | |
209 | } |