Skip to content

Commit 8f8eab1

Browse files
committed
Fix easiest borrowck errors
1 parent a91170d commit 8f8eab1

File tree

7 files changed

+126
-125
lines changed

7 files changed

+126
-125
lines changed

compiler/rustc_infer/src/infer/at.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
192192
{
193193
debug!("sub({:?} <: {:?})", a, b);
194194
let Trace { at, trace, a_is_expected } = self;
195-
at.infcx.commit_if_ok(|_| {
196-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
195+
at.infcx.commit_if_ok(|infcx, _| {
196+
let mut fields = infcx.combine_fields(trace, at.param_env);
197197
fields
198198
.sub(a_is_expected)
199199
.relate(a, b)
@@ -209,8 +209,8 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
209209
{
210210
debug!("eq({:?} == {:?})", a, b);
211211
let Trace { at, trace, a_is_expected } = self;
212-
at.infcx.commit_if_ok(|_| {
213-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
212+
at.infcx.commit_if_ok(|infcx, _| {
213+
let mut fields = infcx.combine_fields(trace, at.param_env);
214214
fields
215215
.equate(a_is_expected)
216216
.relate(a, b)
@@ -224,8 +224,8 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
224224
{
225225
debug!("lub({:?} \\/ {:?})", a, b);
226226
let Trace { at, trace, a_is_expected } = self;
227-
at.infcx.commit_if_ok(|_| {
228-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
227+
at.infcx.commit_if_ok(|infcx, _| {
228+
let mut fields = infcx.combine_fields(trace, at.param_env);
229229
fields
230230
.lub(a_is_expected)
231231
.relate(a, b)
@@ -239,8 +239,8 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
239239
{
240240
debug!("glb({:?} /\\ {:?})", a, b);
241241
let Trace { at, trace, a_is_expected } = self;
242-
at.infcx.commit_if_ok(|_| {
243-
let mut fields = at.infcx.combine_fields(trace, at.param_env);
242+
at.infcx.commit_if_ok(|infcx, _| {
243+
let mut fields = infcx.combine_fields(trace, at.param_env);
244244
fields
245245
.glb(a_is_expected)
246246
.relate(a, b)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
9898
/// variable, then you'll get a new inference variable; if it is a
9999
/// universally quantified variable, you get a placeholder.
100100
fn instantiate_canonical_var(
101-
&self,
101+
&mut self,
102102
span: Span,
103103
cv_info: CanonicalVarInfo<'tcx>,
104104
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
4949
/// - Finally, if any of the obligations result in a hard error,
5050
/// then `Err(NoSolution)` is returned.
5151
pub fn make_canonicalized_query_response<T>(
52-
&self,
52+
&mut self,
5353
inference_vars: CanonicalVarValues<'tcx>,
5454
answer: T,
5555
fulfill_cx: &mut dyn TraitEngine<'tcx>,
@@ -94,7 +94,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
9494
/// Helper for `make_canonicalized_query_response` that does
9595
/// everything up until the final canonicalization.
9696
fn make_query_response<T>(
97-
&self,
97+
&mut self,
9898
inference_vars: CanonicalVarValues<'tcx>,
9999
answer: T,
100100
fulfill_cx: &mut dyn TraitEngine<'tcx>,
@@ -156,7 +156,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
156156
///
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>(
159-
&self,
159+
&mut self,
160160
cause: &ObligationCause<'tcx>,
161161
param_env: ty::ParamEnv<'tcx>,
162162
original_values: &OriginalQueryValues<'tcx>,
@@ -217,7 +217,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
217217
/// - Finally, the query result (of type `R`) is propagated back,
218218
/// after applying the substitution `S`.
219219
pub fn instantiate_nll_query_response_and_region_obligations<R>(
220-
&self,
220+
&mut self,
221221
cause: &ObligationCause<'tcx>,
222222
param_env: ty::ParamEnv<'tcx>,
223223
original_values: &OriginalQueryValues<'tcx>,
@@ -334,7 +334,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
334334
/// assigned to a type variable is unified with an unnormalized
335335
/// projection.
336336
fn query_response_substitution<R>(
337-
&self,
337+
&mut self,
338338
cause: &ObligationCause<'tcx>,
339339
param_env: ty::ParamEnv<'tcx>,
340340
original_values: &OriginalQueryValues<'tcx>,
@@ -374,7 +374,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
374374
/// variable instead. Therefore, the result of this method must be
375375
/// properly unified
376376
fn query_response_substitution_guess<R>(
377-
&self,
377+
&mut self,
378378
cause: &ObligationCause<'tcx>,
379379
original_values: &OriginalQueryValues<'tcx>,
380380
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
@@ -487,7 +487,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
487487
///
488488
/// See also: `query_response_substitution_guess`
489489
fn unify_query_response_substitution_guess<R>(
490-
&self,
490+
&mut self,
491491
cause: &ObligationCause<'tcx>,
492492
param_env: ty::ParamEnv<'tcx>,
493493
original_values: &OriginalQueryValues<'tcx>,
@@ -501,8 +501,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
501501
// canonical variable; this is taken from
502502
// `query_response.var_values` after applying the substitution
503503
// `result_subst`.
504+
let tcx = self.tcx;
504505
let substituted_query_response = |index: BoundVar| -> GenericArg<'tcx> {
505-
query_response.substitute_projected(self.tcx, &result_subst, |v| v.var_values[index])
506+
query_response.substitute_projected(tcx, &result_subst, |v| v.var_values[index])
506507
};
507508

508509
// Unify the original value for each variable with the value
@@ -550,21 +551,21 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
550551
/// Given two sets of values for the same set of canonical variables, unify them.
551552
/// The second set is produced lazily by supplying indices from the first set.
552553
fn unify_canonical_vars(
553-
&self,
554+
&mut self,
554555
cause: &ObligationCause<'tcx>,
555556
param_env: ty::ParamEnv<'tcx>,
556557
variables1: &OriginalQueryValues<'tcx>,
557558
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
558559
) -> InferResult<'tcx, ()> {
559-
self.commit_if_ok(|_| {
560+
self.commit_if_ok(|this, _| {
560561
let mut obligations = vec![];
561562
for (index, value1) in variables1.var_values.iter().enumerate() {
562563
let value2 = variables2(BoundVar::new(index));
563564

564565
match (value1.unpack(), value2.unpack()) {
565566
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
566567
obligations
567-
.extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
568+
.extend(this.at(cause, param_env).eq(v1, v2)?.into_obligations());
568569
}
569570
(
570571
GenericArgKind::Lifetime(ty::ReErased),
@@ -574,10 +575,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
574575
}
575576
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
576577
obligations
577-
.extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
578+
.extend(this.at(cause, param_env).eq(v1, v2)?.into_obligations());
578579
}
579580
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
580-
let ok = self.at(cause, param_env).eq(v1, v2)?;
581+
let ok = this.at(cause, param_env).eq(v1, v2)?;
581582
obligations.extend(ok.into_obligations());
582583
}
583584
_ => {

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub enum RelationDir {
6363

6464
impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
6565
pub fn super_combine_tys<R>(
66-
&self,
66+
&mut self,
6767
relation: &mut R,
6868
a: Ty<'tcx>,
6969
b: Ty<'tcx>,
@@ -120,7 +120,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
120120
}
121121

122122
pub fn super_combine_consts<R>(
123-
&self,
123+
&mut self,
124124
relation: &mut R,
125125
a: &'tcx ty::Const<'tcx>,
126126
b: &'tcx ty::Const<'tcx>,
@@ -220,15 +220,14 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
220220
///
221221
/// See `src/test/ui/const-generics/occurs-check/` for more examples where this is relevant.
222222
fn unify_const_variable(
223-
&self,
223+
&mut self,
224224
param_env: ty::ParamEnv<'tcx>,
225225
target_vid: ty::ConstVid<'tcx>,
226226
ct: &'tcx ty::Const<'tcx>,
227227
vid_is_expected: bool,
228228
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
229229
let (for_universe, span) = {
230-
let mut inner = self.inner;
231-
let variable_table = &mut inner.const_unification_table();
230+
let variable_table = &mut self.inner.const_unification_table();
232231
let var_value = variable_table.probe_value(target_vid);
233232
match var_value.val {
234233
ConstVariableValue::Known { value } => {

compiler/rustc_infer/src/infer/fudge.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
102102
debug!("fudge_inference_if_ok()");
103103

104104
let variable_lengths = self.variable_lengths();
105-
let (mut fudger, value) = self.probe(|_| {
105+
let (mut fudger, value) = self.probe(|this, _| {
106106
match f() {
107107
Ok(value) => {
108-
let value = self.resolve_vars_if_possible(value);
108+
let value = this.resolve_vars_if_possible(value);
109109

110110
// At this point, `value` could in principle refer
111111
// to inference variables that have been created during
112112
// the snapshot. Once we exit `probe()`, those are
113113
// going to be popped, so we will have to
114114
// eliminate any references to them.
115115

116-
let mut inner = self.inner;
116+
let mut inner = this.inner;
117117
let type_vars =
118118
inner.type_variables().vars_since_snapshot(variable_lengths.type_var_len);
119119
let int_vars = vars_since_snapshot(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
3030

3131
let span = self.trace.cause.span;
3232

33-
self.infcx.commit_if_ok(|_| {
33+
self.infcx.commit_if_ok(|infcx, _| {
3434
// First, we instantiate each bound region in the supertype with a
3535
// fresh placeholder region.
36-
let b_prime = self.infcx.replace_bound_vars_with_placeholders(b);
36+
let b_prime = infcx.replace_bound_vars_with_placeholders(b);
3737

3838
// Next, we instantiate each bound region in the subtype
3939
// with a fresh region variable. These region variables --
4040
// but no other pre-existing region variables -- can name
4141
// the placeholders.
4242
let (a_prime, _) =
43-
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, a);
43+
infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, a);
4444

4545
debug!("a_prime={:?}", a_prime);
4646
debug!("b_prime={:?}", b_prime);

0 commit comments

Comments
 (0)