Skip to content

Commit 2b44ba7

Browse files
committed
lots of lifetimes
1 parent 8f8eab1 commit 2b44ba7

File tree

10 files changed

+68
-68
lines changed

10 files changed

+68
-68
lines changed

compiler/rustc_infer/src/infer/at.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ use super::*;
3030
use rustc_middle::ty::relate::{Relate, TypeRelation};
3131
use rustc_middle::ty::Const;
3232

33-
pub struct At<'a, 'tcx> {
34-
pub infcx: &'a InferCtxt<'a, 'tcx>,
35-
pub cause: &'a ObligationCause<'tcx>,
33+
pub struct At<'a, 'b, 'tcx> {
34+
pub infcx: &'b mut InferCtxt<'a, 'tcx>,
35+
pub cause: &'b ObligationCause<'tcx>,
3636
pub param_env: ty::ParamEnv<'tcx>,
3737
}
3838

39-
pub struct Trace<'a, 'tcx> {
40-
at: At<'a, 'tcx>,
39+
pub struct Trace<'a, 'b, 'tcx> {
40+
at: At<'a, 'b, 'tcx>,
4141
a_is_expected: bool,
4242
trace: TypeTrace<'tcx>,
4343
}
4444

4545
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
4646
#[inline]
47-
pub fn at(
48-
&'a self,
49-
cause: &'a ObligationCause<'tcx>,
47+
pub fn at<'b>(
48+
&'b mut self,
49+
cause: &'b ObligationCause<'tcx>,
5050
param_env: ty::ParamEnv<'tcx>,
51-
) -> At<'a, 'tcx> {
51+
) -> At<'a, 'b, 'tcx> {
5252
At { infcx: self, cause, param_env }
5353
}
5454
}
@@ -62,7 +62,7 @@ pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
6262
) -> TypeTrace<'tcx>;
6363
}
6464

65-
impl<'a, 'tcx> At<'a, 'tcx> {
65+
impl<'a, 'b, 'tcx> At<'a, 'b, 'tcx> {
6666
/// Hacky routine for equating two impl headers in coherence.
6767
pub fn eq_impl_headers(
6868
self,
@@ -164,7 +164,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
164164
/// error-reporting, but doesn't actually perform any operation
165165
/// yet (this is useful when you want to set the trace using
166166
/// distinct values from those you wish to operate upon).
167-
pub fn trace<T>(self, expected: T, actual: T) -> Trace<'a, 'tcx>
167+
pub fn trace<T>(self, expected: T, actual: T) -> Trace<'a, 'b, 'tcx>
168168
where
169169
T: ToTrace<'tcx>,
170170
{
@@ -174,7 +174,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
174174
/// Like `trace`, but the expected value is determined by the
175175
/// boolean argument (if true, then the first argument `a` is the
176176
/// "expected" value).
177-
pub fn trace_exp<T>(self, a_is_expected: bool, a: T, b: T) -> Trace<'a, 'tcx>
177+
pub fn trace_exp<T>(self, a_is_expected: bool, a: T, b: T) -> Trace<'a, 'b, 'tcx>
178178
where
179179
T: ToTrace<'tcx>,
180180
{
@@ -183,7 +183,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
183183
}
184184
}
185185

186-
impl<'a, 'tcx> Trace<'a, 'tcx> {
186+
impl<'a, 'b, 'tcx> Trace<'a, 'b, 'tcx> {
187187
/// Makes `a <: b` where `a` may or may not be expected (if
188188
/// `a_is_expected` is true, then `a` is expected).
189189
pub fn sub<T>(self, a: T, b: T) -> InferResult<'tcx, ()>

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
157157
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#processing-the-canonicalized-query-result
158158
pub fn instantiate_query_response_and_region_obligations<R>(
159159
&mut self,
160-
cause: &ObligationCause<'tcx>,
160+
cause: &'cx ObligationCause<'tcx>,
161161
param_env: ty::ParamEnv<'tcx>,
162162
original_values: &OriginalQueryValues<'tcx>,
163163
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
@@ -335,7 +335,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
335335
/// projection.
336336
fn query_response_substitution<R>(
337337
&mut self,
338-
cause: &ObligationCause<'tcx>,
338+
cause: &'cx ObligationCause<'tcx>,
339339
param_env: ty::ParamEnv<'tcx>,
340340
original_values: &OriginalQueryValues<'tcx>,
341341
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
@@ -488,7 +488,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
488488
/// See also: `query_response_substitution_guess`
489489
fn unify_query_response_substitution_guess<R>(
490490
&mut self,
491-
cause: &ObligationCause<'tcx>,
491+
cause: &'cx ObligationCause<'tcx>,
492492
param_env: ty::ParamEnv<'tcx>,
493493
original_values: &OriginalQueryValues<'tcx>,
494494
result_subst: &CanonicalVarValues<'tcx>,
@@ -552,7 +552,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
552552
/// The second set is produced lazily by supplying indices from the first set.
553553
fn unify_canonical_vars(
554554
&mut self,
555-
cause: &ObligationCause<'tcx>,
555+
cause: &'cx ObligationCause<'tcx>,
556556
param_env: ty::ParamEnv<'tcx>,
557557
variables1: &OriginalQueryValues<'tcx>,
558558
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
4545
use rustc_middle::ty::{IntType, UintType};
4646
use rustc_span::{Span, DUMMY_SP};
4747

48-
#[derive(Clone)]
49-
pub struct CombineFields<'infcx, 'tcx> {
50-
pub infcx: &'infcx InferCtxt<'infcx, 'tcx>,
48+
pub struct CombineFields<'a, 'infcx, 'tcx> {
49+
pub infcx: &'a mut InferCtxt<'infcx, 'tcx>,
5150
pub trace: TypeTrace<'tcx>,
5251
pub cause: Option<ty::relate::Cause>,
5352
pub param_env: ty::ParamEnv<'tcx>,
@@ -285,24 +284,24 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
285284
}
286285
}
287286

288-
impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
287+
impl<'infcx_borrow, 'infcx, 'tcx> CombineFields<'infcx_borrow, 'infcx, 'tcx> {
289288
pub fn tcx(&self) -> TyCtxt<'tcx> {
290289
self.infcx.tcx
291290
}
292291

293-
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> Equate<'a, 'infcx, 'tcx> {
292+
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> Equate<'a, 'infcx_borrow, 'infcx, 'tcx> {
294293
Equate::new(self, a_is_expected)
295294
}
296295

297-
pub fn sub<'a>(&'a mut self, a_is_expected: bool) -> Sub<'a, 'infcx, 'tcx> {
296+
pub fn sub<'a>(&'a mut self, a_is_expected: bool) -> Sub<'a, 'infcx_borrow, 'infcx, 'tcx> {
298297
Sub::new(self, a_is_expected)
299298
}
300299

301-
pub fn lub<'a>(&'a mut self, a_is_expected: bool) -> Lub<'a, 'infcx, 'tcx> {
300+
pub fn lub<'a>(&'a mut self, a_is_expected: bool) -> Lub<'a, 'infcx_borrow, 'infcx, 'tcx> {
302301
Lub::new(self, a_is_expected)
303302
}
304303

305-
pub fn glb<'a>(&'a mut self, a_is_expected: bool) -> Glb<'a, 'infcx, 'tcx> {
304+
pub fn glb<'a>(&'a mut self, a_is_expected: bool) -> Glb<'a, 'infcx_borrow, 'infcx, 'tcx> {
306305
Glb::new(self, a_is_expected)
307306
}
308307

@@ -456,11 +455,11 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
456455
}
457456
}
458457

459-
struct Generalizer<'cx, 'tcx> {
460-
infcx: &'cx InferCtxt<'cx, 'tcx>,
458+
struct Generalizer<'a, 'cx, 'tcx> {
459+
infcx: &'a mut InferCtxt<'cx, 'tcx>,
461460

462461
/// The span, used when creating new type variables and things.
463-
cause: &'cx ObligationCause<'tcx>,
462+
cause: &'a ObligationCause<'tcx>,
464463

465464
/// The vid of the type variable that is in the process of being
466465
/// instantiated; if we find this within the type we are folding,
@@ -520,7 +519,7 @@ struct Generalization<'tcx> {
520519
needs_wf: bool,
521520
}
522521

523-
impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
522+
impl TypeRelation<'tcx> for Generalizer<'_, '_, 'tcx> {
524523
fn tcx(&self) -> TyCtxt<'tcx> {
525524
self.infcx.tcx
526525
}

compiler/rustc_infer/src/infer/equate.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
99
use rustc_hir::def_id::DefId;
1010

1111
/// Ensures `a` is made equal to `b`. Returns `a` on success.
12-
pub struct Equate<'combine, 'infcx, 'tcx> {
13-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
12+
pub struct Equate<'s, 'combine, 'infcx, 'tcx> {
13+
// TODO: 'combine looks wrong
14+
fields: &'s mut CombineFields<'combine, 'infcx, 'tcx>,
1415
a_is_expected: bool,
1516
}
1617

17-
impl<'combine, 'infcx, 'tcx> Equate<'combine, 'infcx, 'tcx> {
18+
impl<'s, 'combine, 'infcx, 'tcx> Equate<'s, 'combine, 'infcx, 'tcx> {
1819
pub fn new(
19-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
20+
fields: &'s mut CombineFields<'combine, 'infcx, 'tcx>,
2021
a_is_expected: bool,
21-
) -> Equate<'combine, 'infcx, 'tcx> {
22+
) -> Self {
2223
Equate { fields, a_is_expected }
2324
}
2425
}
2526

26-
impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
27+
impl TypeRelation<'tcx> for Equate<'_, 'combine, 'infcx, 'tcx> {
2728
fn tag(&self) -> &'static str {
2829
"Equate"
2930
}
@@ -140,7 +141,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
140141
}
141142
}
142143

143-
impl<'tcx> ConstEquateRelation<'tcx> for Equate<'_, '_, 'tcx> {
144+
impl<'tcx> ConstEquateRelation<'tcx> for Equate<'_, '_, '_, 'tcx> {
144145
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) {
145146
self.fields.add_const_equate_obligation(self.a_is_expected, a, b);
146147
}

compiler/rustc_infer/src/infer/glb.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
99
use rustc_middle::ty::{self, Ty, TyCtxt};
1010

1111
/// "Greatest lower bound" (common subtype)
12-
pub struct Glb<'combine, 'infcx, 'tcx> {
13-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
12+
pub struct Glb<'combine_borrow, 'combine, 'infcx, 'tcx> {
13+
fields: &'combine_borrow mut CombineFields<'combine, 'infcx, 'tcx>,
1414
a_is_expected: bool,
1515
}
1616

17-
impl<'combine, 'infcx, 'tcx> Glb<'combine, 'infcx, 'tcx> {
17+
impl<'combine_borrow, 'combine, 'infcx, 'tcx> Glb<'combine_borrow, 'combine, 'infcx, 'tcx> {
1818
pub fn new(
19-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
19+
fields: &'combine_borrow mut CombineFields<'combine, 'infcx, 'tcx>,
2020
a_is_expected: bool,
21-
) -> Glb<'combine, 'infcx, 'tcx> {
21+
) -> Glb<'combine_borrow, 'combine, 'infcx, 'tcx> {
2222
Glb { fields, a_is_expected }
2323
}
2424
}
2525

26-
impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
26+
impl TypeRelation<'tcx> for Glb<'_, 'combine, 'infcx, 'tcx> {
2727
fn tag(&self) -> &'static str {
2828
"Glb"
2929
}
@@ -101,8 +101,8 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
101101
}
102102
}
103103

104-
impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx, 'tcx> {
105-
fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'tcx> {
104+
impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'_, 'combine, 'infcx, 'tcx> {
105+
fn infcx(&self) -> &InferCtxt<'infcx, 'tcx> {
106106
self.fields.infcx
107107
}
108108

@@ -118,7 +118,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx,
118118
}
119119
}
120120

121-
impl<'tcx> ConstEquateRelation<'tcx> for Glb<'_, '_, 'tcx> {
121+
impl<'tcx> ConstEquateRelation<'tcx> for Glb<'_, '_, '_, 'tcx> {
122122
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) {
123123
self.fields.add_const_equate_obligation(self.a_is_expected, a, b);
124124
}

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::infer::CombinedSnapshot;
88
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
99
use rustc_middle::ty::{self, Binder, TypeFoldable};
1010

11-
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
11+
impl<'a, 'tcx> CombineFields<'_, 'a, 'tcx> {
1212
pub fn higher_ranked_sub<T>(
1313
&mut self,
1414
a: Binder<T>,

compiler/rustc_infer/src/infer/lattice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::ty::TyVar;
2828
use rustc_middle::ty::{self, Ty};
2929

3030
pub trait LatticeDir<'f, 'tcx>: TypeRelation<'tcx> {
31-
fn infcx(&self) -> &'f InferCtxt<'f, 'tcx>;
31+
fn infcx(&self) -> &InferCtxt<'f, 'tcx>;
3232

3333
fn cause(&self) -> &ObligationCause<'tcx>;
3434

compiler/rustc_infer/src/infer/lub.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
99
use rustc_middle::ty::{self, Ty, TyCtxt};
1010

1111
/// "Least upper bound" (common supertype)
12-
pub struct Lub<'combine, 'infcx, 'tcx> {
13-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
12+
pub struct Lub<'combine_borrow, 'combine, 'infcx, 'tcx> {
13+
fields: &'combine_borrow mut CombineFields<'combine, 'infcx, 'tcx>,
1414
a_is_expected: bool,
1515
}
1616

17-
impl<'combine, 'infcx, 'tcx> Lub<'combine, 'infcx, 'tcx> {
17+
impl<'combine_borrow, 'combine, 'infcx, 'tcx> Lub<'combine_borrow, 'combine, 'infcx, 'tcx> {
1818
pub fn new(
19-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
19+
fields: &'combine_borrow mut CombineFields<'combine, 'infcx, 'tcx>,
2020
a_is_expected: bool,
21-
) -> Lub<'combine, 'infcx, 'tcx> {
21+
) -> Lub<'combine_borrow, 'combine, 'infcx, 'tcx> {
2222
Lub { fields, a_is_expected }
2323
}
2424
}
2525

26-
impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
26+
impl TypeRelation<'tcx> for Lub<'_, 'combine, 'infcx, 'tcx> {
2727
fn tag(&self) -> &'static str {
2828
"Lub"
2929
}
@@ -101,14 +101,14 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
101101
}
102102
}
103103

104-
impl<'tcx> ConstEquateRelation<'tcx> for Lub<'_, '_, 'tcx> {
104+
impl<'tcx> ConstEquateRelation<'tcx> for Lub<'_, '_, '_, 'tcx> {
105105
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) {
106106
self.fields.add_const_equate_obligation(self.a_is_expected, a, b);
107107
}
108108
}
109109

110-
impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx, 'tcx> {
111-
fn infcx(&self) -> &'infcx InferCtxt<'infcx, 'tcx> {
110+
impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'_, 'combine, 'infcx, 'tcx> {
111+
fn infcx(&self) -> &InferCtxt<'infcx, 'tcx> {
112112
self.fields.infcx
113113
}
114114

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
697697
vars
698698
}
699699

700-
fn combine_fields(
701-
&'a self,
700+
fn combine_fields<'s>(
701+
&'s mut self,
702702
trace: TypeTrace<'tcx>,
703703
param_env: ty::ParamEnv<'tcx>,
704-
) -> CombineFields<'a, 'tcx> {
704+
) -> CombineFields<'s, 'a, 'tcx> {
705705
CombineFields {
706706
infcx: self,
707707
trace,
@@ -802,7 +802,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
802802
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`.
803803
pub fn commit_if_ok<T, E, F>(&mut self, f: F) -> Result<T, E>
804804
where
805-
F: FnOnce(&mut Self, &CombinedSnapshot<'a, 'tcx>) -> Result<T, E>,
805+
F: for<'s> FnOnce(&'s mut Self, &CombinedSnapshot<'a, 'tcx>) -> Result<T, E>,
806806
{
807807
debug!("commit_if_ok()");
808808
let snapshot = self.start_snapshot();
@@ -924,7 +924,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
924924

925925
pub fn subtype_predicate(
926926
&mut self,
927-
cause: &ObligationCause<'tcx>,
927+
cause: &'a ObligationCause<'tcx>,
928928
param_env: ty::ParamEnv<'tcx>,
929929
predicate: ty::PolySubtypePredicate<'tcx>,
930930
) -> Option<InferResult<'tcx, ()>> {

compiler/rustc_infer/src/infer/sub.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
1010
use std::mem;
1111

1212
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
13-
pub struct Sub<'combine, 'infcx, 'tcx> {
14-
fields: &'combine mut CombineFields<'infcx, 'tcx>,
13+
pub struct Sub<'combine_borrow, 'combine, 'infcx, 'tcx> {
14+
fields: &'combine_borrow mut CombineFields<'combine, 'infcx, 'tcx>,
1515
a_is_expected: bool,
1616
}
1717

18-
impl<'combine, 'infcx, 'tcx> Sub<'combine, 'infcx, 'tcx> {
18+
impl<'combine_borrow, 'combine, 'infcx, 'tcx> Sub<'combine_borrow, 'combine, 'infcx, 'tcx> {
1919
pub fn new(
20-
f: &'combine mut CombineFields<'infcx, 'tcx>,
20+
f: &'combine_borrow mut CombineFields<'combine, 'infcx, 'tcx>,
2121
a_is_expected: bool,
22-
) -> Sub<'combine, 'infcx, 'tcx> {
22+
) -> Sub<'combine_borrow, 'combine, 'infcx, 'tcx> {
2323
Sub { fields: f, a_is_expected }
2424
}
2525

@@ -31,7 +31,7 @@ impl<'combine, 'infcx, 'tcx> Sub<'combine, 'infcx, 'tcx> {
3131
}
3232
}
3333

34-
impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
34+
impl TypeRelation<'tcx> for Sub<'_, 'combine, 'infcx, 'tcx> {
3535
fn tag(&self) -> &'static str {
3636
"Sub"
3737
}
@@ -171,7 +171,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
171171
}
172172
}
173173

174-
impl<'tcx> ConstEquateRelation<'tcx> for Sub<'_, '_, 'tcx> {
174+
impl<'tcx> ConstEquateRelation<'tcx> for Sub<'_, '_, '_, 'tcx> {
175175
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>) {
176176
self.fields.add_const_equate_obligation(self.a_is_expected, a, b);
177177
}

0 commit comments

Comments
 (0)