Skip to content

Commit 41ff402

Browse files
committed
Fix borrow checker warning
1 parent 56c57ee commit 41ff402

File tree

4 files changed

+91
-32
lines changed

4 files changed

+91
-32
lines changed

chalk-ir/src/could_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
interner: &'i I,
2121
};
2222

23-
impl<I: Interner> Zipper<I> for MatchZipper<'_, I> {
23+
impl<'i, I: Interner> Zipper<'i, I> for MatchZipper<'i, I> {
2424
fn zip_tys(&mut self, a: &Ty<I>, b: &Ty<I>) -> Fallible<()> {
2525
let could_match = match (a.data(self.interner), b.data(self.interner)) {
2626
(&TyData::Apply(ref a), &TyData::Apply(ref b)) => {
@@ -54,7 +54,7 @@ where
5454
Zip::zip_with(self, &a.value, &b.value)
5555
}
5656

57-
fn interner(&self) -> &I {
57+
fn interner(&self) -> &'i I {
5858
self.interner
5959
}
6060
}

chalk-ir/src/zip.rs

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::sync::Arc;
1919
/// represented by two distinct `ItemId` values, and the impl for
2020
/// `ItemId` requires that all `ItemId` in the two zipped values match
2121
/// up.
22-
pub trait Zipper<I: Interner> {
22+
pub trait Zipper<'i, I: Interner> {
2323
/// Indicates that the two types `a` and `b` were found in
2424
/// matching spots, beneath `binders` levels of binders.
2525
fn zip_tys(&mut self, a: &Ty<I>, b: &Ty<I>) -> Fallible<()>;
@@ -34,13 +34,13 @@ pub trait Zipper<I: Interner> {
3434
T: Zip<I> + Fold<I, I, Result = T>;
3535

3636
/// Retreives the interner from the underlying zipper object
37-
fn interner(&self) -> &I;
37+
fn interner(&self) -> &'i I;
3838
}
3939

40-
impl<'f, Z, I> Zipper<I> for &'f mut Z
40+
impl<'f, 'i, Z, I> Zipper<'i, I> for &'f mut Z
4141
where
4242
I: Interner,
43-
Z: Zipper<I>,
43+
Z: Zipper<'i, I>,
4444
{
4545
fn zip_tys(&mut self, a: &Ty<I>, b: &Ty<I>) -> Fallible<()> {
4646
(**self).zip_tys(a, b)
@@ -57,7 +57,7 @@ where
5757
(**self).zip_binders(a, b)
5858
}
5959

60-
fn interner(&self) -> &I {
60+
fn interner(&self) -> &'i I {
6161
Z::interner(*self)
6262
}
6363
}
@@ -73,29 +73,40 @@ pub trait Zip<I>: Debug
7373
where
7474
I: Interner,
7575
{
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;
7779
}
7880

7981
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+
{
8186
<T as Zip<I>>::zip_with(zipper, a, b)
8287
}
8388
}
8489

8590
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<()> {
8792
Ok(())
8893
}
8994
}
9095

9196
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+
{
93101
<[T] as Zip<I>>::zip_with(zipper, a, b)
94102
}
95103
}
96104

97105
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+
{
99110
if a.len() != b.len() {
100111
return Err(NoSolution);
101112
}
@@ -109,39 +120,57 @@ impl<T: Zip<I>, I: Interner> Zip<I> for [T] {
109120
}
110121

111122
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+
{
113127
<T as Zip<I>>::zip_with(zipper, a, b)
114128
}
115129
}
116130

117131
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+
{
119136
<T as Zip<I>>::zip_with(zipper, a, b)
120137
}
121138
}
122139

123140
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+
{
125145
Zip::zip_with(zipper, &a.0, &b.0)?;
126146
Zip::zip_with(zipper, &a.1, &b.1)?;
127147
Ok(())
128148
}
129149
}
130150

131151
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+
{
133156
zipper.zip_tys(a, b)
134157
}
135158
}
136159

137160
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+
{
139165
zipper.zip_lifetimes(a, b)
140166
}
141167
}
142168

143169
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+
{
145174
zipper.zip_binders(a, b)
146175
}
147176
}
@@ -151,7 +180,10 @@ impl<I: Interner, T: Zip<I> + Fold<I, I, Result = T>> Zip<I> for Binders<T> {
151180
macro_rules! eq_zip {
152181
($I:ident => $t:ty) => {
153182
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+
{
155187
if a != b {
156188
return Err(NoSolution);
157189
}
@@ -173,7 +205,10 @@ eq_zip!(I => PlaceholderIndex);
173205
macro_rules! struct_zip {
174206
(impl[$($param:tt)*] Zip<$I:ty> for $self:ty { $($field:ident),* $(,)* } $($w:tt)*) => {
175207
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+
{
177212
// Validate that we have indeed listed all fields
178213
let Self { $($field: _),* } = *a;
179214
$(
@@ -211,15 +246,21 @@ struct_zip!(impl[I: Interner] Zip<I> for ProgramClauseImplication<I> {
211246
});
212247

213248
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+
{
215253
assert_eq!(a.clauses.len(), b.clauses.len()); // or different numbers of clauses
216254
Zip::zip_with(zipper, &a.clauses, &b.clauses)?;
217255
Ok(())
218256
}
219257
}
220258

221259
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+
{
223264
Zip::zip_with(zipper, a.as_slice(), b.as_slice())?;
224265
Ok(())
225266
}
@@ -231,7 +272,10 @@ impl<I: Interner> Zip<I> for Goals<I> {
231272
macro_rules! enum_zip {
232273
(impl<$I:ident $(, $param:ident)*> for $self:ty { $( $variant:ident ),* $(,)* } $($w:tt)*) => {
233274
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+
{
235279
match (a, b) {
236280
$(
237281
(Self :: $variant (f_a), Self :: $variant (f_b)) => {
@@ -267,7 +311,10 @@ enum_zip!(impl<I> for DomainGoal<I> {
267311
enum_zip!(impl<I> for ProgramClause<I> { Implies, ForAll });
268312

269313
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+
{
271318
Zip::zip_with(zipper, a.parameters(), b.parameters())
272319
}
273320
}
@@ -276,13 +323,19 @@ impl<I: Interner> Zip<I> for Substitution<I> {
276323
// two parameters, and I'm too lazy to make the macro account for the
277324
// relevant name mangling.
278325
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+
{
280330
Zip::zip_with(zipper, a.data(), b.data())
281331
}
282332
}
283333

284334
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+
{
286339
match (a, b) {
287340
(&GoalData::Quantified(ref f_a, ref g_a), &GoalData::Quantified(ref f_b, ref g_b)) => {
288341
Zip::zip_with(zipper, f_a, f_b)?;
@@ -316,7 +369,10 @@ impl<I: Interner> Zip<I> for GoalData<I> {
316369

317370
// I'm too lazy to make `enum_zip` support type parameters.
318371
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+
{
320376
match (a, b) {
321377
(ParameterKind::Ty(a), ParameterKind::Ty(b)) => Zip::zip_with(zipper, a, b),
322378
(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> {
329385

330386
#[allow(unreachable_code, unused_variables)]
331387
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+
{
333392
let interner = zipper.interner();
334393
Zip::zip_with(zipper, a.data(interner), b.data(interner))
335394
}

chalk-solve/src/infer/unify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl<'t, I: Interner> Unifier<'t, I> {
338338
}
339339
}
340340

341-
impl<I: Interner> Zipper<I> for Unifier<'_, I> {
341+
impl<'i, I: Interner> Zipper<'i, I> for Unifier<'i, I> {
342342
fn zip_tys(&mut self, a: &Ty<I>, b: &Ty<I>) -> Fallible<()> {
343343
self.unify_ty_ty(a, b)
344344
}
@@ -365,7 +365,7 @@ impl<I: Interner> Zipper<I> for Unifier<'_, I> {
365365
self.unify_binders(a, b)
366366
}
367367

368-
fn interner(&self) -> &I {
368+
fn interner(&self) -> &'i I {
369369
self.interner
370370
}
371371
}

chalk-solve/src/solve/slg/resolvent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl<I: Interner> AnswerSubstitutor<'_, I> {
352352
}
353353
}
354354

355-
impl<I: Interner> Zipper<I> for AnswerSubstitutor<'_, I> {
355+
impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> {
356356
fn zip_tys(&mut self, answer: &Ty<I>, pending: &Ty<I>) -> Fallible<()> {
357357
let interner = self.interner;
358358

@@ -465,7 +465,7 @@ impl<I: Interner> Zipper<I> for AnswerSubstitutor<'_, I> {
465465
Ok(())
466466
}
467467

468-
fn interner(&self) -> &I {
468+
fn interner(&self) -> &'i I {
469469
self.interner
470470
}
471471
}

0 commit comments

Comments
 (0)