@@ -19,7 +19,7 @@ use std::sync::Arc;
19
19
/// represented by two distinct `ItemId` values, and the impl for
20
20
/// `ItemId` requires that all `ItemId` in the two zipped values match
21
21
/// up.
22
- pub trait Zipper < I : Interner > {
22
+ pub trait Zipper < ' i , I : Interner > {
23
23
/// Indicates that the two types `a` and `b` were found in
24
24
/// matching spots, beneath `binders` levels of binders.
25
25
fn zip_tys ( & mut self , a : & Ty < I > , b : & Ty < I > ) -> Fallible < ( ) > ;
@@ -34,13 +34,13 @@ pub trait Zipper<I: Interner> {
34
34
T : Zip < I > + Fold < I , I , Result = T > ;
35
35
36
36
/// Retreives the interner from the underlying zipper object
37
- fn interner ( & self ) -> & I ;
37
+ fn interner ( & self ) -> & ' i I ;
38
38
}
39
39
40
- impl < ' f , Z , I > Zipper < I > for & ' f mut Z
40
+ impl < ' f , ' i , Z , I > Zipper < ' i , I > for & ' f mut Z
41
41
where
42
42
I : Interner ,
43
- Z : Zipper < I > ,
43
+ Z : Zipper < ' i , I > ,
44
44
{
45
45
fn zip_tys ( & mut self , a : & Ty < I > , b : & Ty < I > ) -> Fallible < ( ) > {
46
46
( * * self ) . zip_tys ( a, b)
57
57
( * * self ) . zip_binders ( a, b)
58
58
}
59
59
60
- fn interner ( & self ) -> & I {
60
+ fn interner ( & self ) -> & ' i I {
61
61
Z :: interner ( * self )
62
62
}
63
63
}
@@ -73,29 +73,40 @@ pub trait Zip<I>: Debug
73
73
where
74
74
I : Interner ,
75
75
{
76
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > ;
76
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
77
+ where
78
+ I : ' i ;
77
79
}
78
80
79
81
impl < ' a , T : ?Sized + Zip < I > , I : Interner > Zip < I > for & ' a T {
80
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
82
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
83
+ where
84
+ I : ' i ,
85
+ {
81
86
<T as Zip < I > >:: zip_with ( zipper, a, b)
82
87
}
83
88
}
84
89
85
90
impl < I : Interner > Zip < I > for ( ) {
86
- fn zip_with < Z : Zipper < I > > ( _: & mut Z , _: & Self , _: & Self ) -> Fallible < ( ) > {
91
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( _: & mut Z , _: & Self , _: & Self ) -> Fallible < ( ) > {
87
92
Ok ( ( ) )
88
93
}
89
94
}
90
95
91
96
impl < T : Zip < I > , I : Interner > Zip < I > for Vec < T > {
92
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
97
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
98
+ where
99
+ I : ' i ,
100
+ {
93
101
<[ T ] as Zip < I > >:: zip_with ( zipper, a, b)
94
102
}
95
103
}
96
104
97
105
impl < T : Zip < I > , I : Interner > Zip < I > for [ T ] {
98
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
106
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
107
+ where
108
+ I : ' i ,
109
+ {
99
110
if a. len ( ) != b. len ( ) {
100
111
return Err ( NoSolution ) ;
101
112
}
@@ -109,39 +120,57 @@ impl<T: Zip<I>, I: Interner> Zip<I> for [T] {
109
120
}
110
121
111
122
impl < T : Zip < I > , I : Interner > Zip < I > for Arc < T > {
112
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
123
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
124
+ where
125
+ I : ' i ,
126
+ {
113
127
<T as Zip < I > >:: zip_with ( zipper, a, b)
114
128
}
115
129
}
116
130
117
131
impl < T : Zip < I > , I : Interner > Zip < I > for Box < T > {
118
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
132
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
133
+ where
134
+ I : ' i ,
135
+ {
119
136
<T as Zip < I > >:: zip_with ( zipper, a, b)
120
137
}
121
138
}
122
139
123
140
impl < T : Zip < I > , U : Zip < I > , I : Interner > Zip < I > for ( T , U ) {
124
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
141
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
142
+ where
143
+ I : ' i ,
144
+ {
125
145
Zip :: zip_with ( zipper, & a. 0 , & b. 0 ) ?;
126
146
Zip :: zip_with ( zipper, & a. 1 , & b. 1 ) ?;
127
147
Ok ( ( ) )
128
148
}
129
149
}
130
150
131
151
impl < I : Interner > Zip < I > for Ty < I > {
132
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
152
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
153
+ where
154
+ I : ' i ,
155
+ {
133
156
zipper. zip_tys ( a, b)
134
157
}
135
158
}
136
159
137
160
impl < I : Interner > Zip < I > for Lifetime < I > {
138
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
161
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
162
+ where
163
+ I : ' i ,
164
+ {
139
165
zipper. zip_lifetimes ( a, b)
140
166
}
141
167
}
142
168
143
169
impl < I : Interner , T : Zip < I > + Fold < I , I , Result = T > > Zip < I > for Binders < T > {
144
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
170
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
171
+ where
172
+ I : ' i ,
173
+ {
145
174
zipper. zip_binders ( a, b)
146
175
}
147
176
}
@@ -151,7 +180,10 @@ impl<I: Interner, T: Zip<I> + Fold<I, I, Result = T>> Zip<I> for Binders<T> {
151
180
macro_rules! eq_zip {
152
181
( $I: ident => $t: ty) => {
153
182
impl <$I: Interner > Zip <$I> for $t {
154
- fn zip_with<Z : Zipper <$I>>( _zipper: & mut Z , a: & Self , b: & Self ) -> Fallible <( ) > {
183
+ fn zip_with<' i, Z : Zipper <' i, $I>>( _zipper: & mut Z , a: & Self , b: & Self ) -> Fallible <( ) >
184
+ where
185
+ I : ' i,
186
+ {
155
187
if a != b {
156
188
return Err ( NoSolution ) ;
157
189
}
@@ -173,7 +205,10 @@ eq_zip!(I => PlaceholderIndex);
173
205
macro_rules! struct_zip {
174
206
( impl [ $( $param: tt) * ] Zip <$I: ty> for $self: ty { $( $field: ident) ,* $( , ) * } $( $w: tt) * ) => {
175
207
impl <$( $param) * > Zip <$I> for $self $( $w) * {
176
- fn zip_with<Z : Zipper <$I>>( zipper: & mut Z , a: & Self , b: & Self ) -> Fallible <( ) > {
208
+ fn zip_with<' i, Z : Zipper <' i, $I>>( zipper: & mut Z , a: & Self , b: & Self ) -> Fallible <( ) >
209
+ where
210
+ I : ' i,
211
+ {
177
212
// Validate that we have indeed listed all fields
178
213
let Self { $( $field: _) ,* } = * a;
179
214
$(
@@ -211,15 +246,21 @@ struct_zip!(impl[I: Interner] Zip<I> for ProgramClauseImplication<I> {
211
246
} ) ;
212
247
213
248
impl < I : Interner > Zip < I > for Environment < I > {
214
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
249
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
250
+ where
251
+ I : ' i ,
252
+ {
215
253
assert_eq ! ( a. clauses. len( ) , b. clauses. len( ) ) ; // or different numbers of clauses
216
254
Zip :: zip_with ( zipper, & a. clauses , & b. clauses ) ?;
217
255
Ok ( ( ) )
218
256
}
219
257
}
220
258
221
259
impl < I : Interner > Zip < I > for Goals < I > {
222
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
260
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
261
+ where
262
+ I : ' i ,
263
+ {
223
264
Zip :: zip_with ( zipper, a. as_slice ( ) , b. as_slice ( ) ) ?;
224
265
Ok ( ( ) )
225
266
}
@@ -231,7 +272,10 @@ impl<I: Interner> Zip<I> for Goals<I> {
231
272
macro_rules! enum_zip {
232
273
( impl <$I: ident $( , $param: ident) * > for $self: ty { $( $variant: ident ) ,* $( , ) * } $( $w: tt) * ) => {
233
274
impl <$I: Interner , $( , $param) * > Zip <$I> for $self $( $w) * {
234
- fn zip_with<Z : Zipper <$I>>( zipper: & mut Z , a: & Self , b: & Self ) -> Fallible <( ) > {
275
+ fn zip_with<' i, Z : Zipper <' i, $I>>( zipper: & mut Z , a: & Self , b: & Self ) -> Fallible <( ) >
276
+ where
277
+ I : ' i,
278
+ {
235
279
match ( a, b) {
236
280
$(
237
281
( Self :: $variant ( f_a) , Self :: $variant ( f_b) ) => {
@@ -267,7 +311,10 @@ enum_zip!(impl<I> for DomainGoal<I> {
267
311
enum_zip ! ( impl <I > for ProgramClause <I > { Implies , ForAll } ) ;
268
312
269
313
impl < I : Interner > Zip < I > for Substitution < I > {
270
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
314
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
315
+ where
316
+ I : ' i ,
317
+ {
271
318
Zip :: zip_with ( zipper, a. parameters ( ) , b. parameters ( ) )
272
319
}
273
320
}
@@ -276,13 +323,19 @@ impl<I: Interner> Zip<I> for Substitution<I> {
276
323
// two parameters, and I'm too lazy to make the macro account for the
277
324
// relevant name mangling.
278
325
impl < I : Interner > Zip < I > for Goal < I > {
279
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
326
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
327
+ where
328
+ I : ' i ,
329
+ {
280
330
Zip :: zip_with ( zipper, a. data ( ) , b. data ( ) )
281
331
}
282
332
}
283
333
284
334
impl < I : Interner > Zip < I > for GoalData < I > {
285
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
335
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
336
+ where
337
+ I : ' i ,
338
+ {
286
339
match ( a, b) {
287
340
( & GoalData :: Quantified ( ref f_a, ref g_a) , & GoalData :: Quantified ( ref f_b, ref g_b) ) => {
288
341
Zip :: zip_with ( zipper, f_a, f_b) ?;
@@ -316,7 +369,10 @@ impl<I: Interner> Zip<I> for GoalData<I> {
316
369
317
370
// I'm too lazy to make `enum_zip` support type parameters.
318
371
impl < T : Zip < I > , L : Zip < I > , I : Interner > Zip < I > for ParameterKind < T , L > {
319
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
372
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
373
+ where
374
+ I : ' i ,
375
+ {
320
376
match ( a, b) {
321
377
( ParameterKind :: Ty ( a) , ParameterKind :: Ty ( b) ) => Zip :: zip_with ( zipper, a, b) ,
322
378
( ParameterKind :: Lifetime ( a) , ParameterKind :: Lifetime ( b) ) => Zip :: zip_with ( zipper, a, b) ,
@@ -329,7 +385,10 @@ impl<T: Zip<I>, L: Zip<I>, I: Interner> Zip<I> for ParameterKind<T, L> {
329
385
330
386
#[ allow( unreachable_code, unused_variables) ]
331
387
impl < I : Interner > Zip < I > for Parameter < I > {
332
- fn zip_with < Z : Zipper < I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) > {
388
+ fn zip_with < ' i , Z : Zipper < ' i , I > > ( zipper : & mut Z , a : & Self , b : & Self ) -> Fallible < ( ) >
389
+ where
390
+ I : ' i ,
391
+ {
333
392
let interner = zipper. interner ( ) ;
334
393
Zip :: zip_with ( zipper, a. data ( interner) , b. data ( interner) )
335
394
}
0 commit comments