Skip to content

Commit dad3dc4

Browse files
committed
Make infcx mut in TypeFreshener
1 parent db3ac4e commit dad3dc4

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ use std::collections::hash_map::Entry;
4141
use super::unify_key::ToType;
4242
use super::InferCtxt;
4343

44-
pub struct TypeFreshener<'a, 'tcx> {
45-
infcx: &'a InferCtxt<'a, 'tcx>,
44+
pub struct TypeFreshener<'a, 'cx, 'tcx> {
45+
infcx: &'a mut InferCtxt<'cx, 'tcx>,
4646
ty_freshen_count: u32,
4747
const_freshen_count: u32,
4848
ty_freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
4949
const_freshen_map: FxHashMap<ty::InferConst<'tcx>, &'tcx ty::Const<'tcx>>,
5050
}
5151

52-
impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
53-
pub fn new(infcx: &'a InferCtxt<'a, 'tcx>) -> TypeFreshener<'a, 'tcx> {
52+
impl<'a, 'cx, 'tcx> TypeFreshener<'a, 'cx, 'tcx> {
53+
pub fn new(infcx: &'a mut InferCtxt<'cx, 'tcx>) -> Self {
5454
TypeFreshener {
5555
infcx,
5656
ty_freshen_count: 0,
@@ -112,7 +112,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
112112
}
113113
}
114114

115-
impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
115+
impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, '_, 'tcx> {
116116
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
117117
self.infcx.tcx
118118
}
@@ -150,25 +150,31 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
150150
self.freshen_ty(opt_ty, ty::TyVar(v), ty::FreshTy)
151151
}
152152

153-
ty::Infer(ty::IntVar(v)) => self.freshen_ty(
154-
self.infcx
153+
ty::Infer(ty::IntVar(v)) => {
154+
let opt_ty = self.infcx
155155
.inner
156156
.int_unification_table()
157157
.probe_value(v)
158-
.map(|v| v.to_type(tcx)),
159-
ty::IntVar(v),
160-
ty::FreshIntTy,
161-
),
158+
.map(|v| v.to_type(tcx));
159+
self.freshen_ty(
160+
opt_ty,
161+
ty::IntVar(v),
162+
ty::FreshIntTy,
163+
)
164+
}
162165

163-
ty::Infer(ty::FloatVar(v)) => self.freshen_ty(
164-
self.infcx
166+
ty::Infer(ty::FloatVar(v)) => {
167+
let opt_ty = self.infcx
165168
.inner
166169
.float_unification_table()
167170
.probe_value(v)
168-
.map(|v| v.to_type(tcx)),
171+
.map(|v| v.to_type(tcx));
172+
self.freshen_ty(
173+
opt_ty,
169174
ty::FloatVar(v),
170175
ty::FreshFloatTy,
171-
),
176+
)
177+
}
172178

173179
ty::Infer(ty::FreshTy(ct) | ty::FreshIntTy(ct) | ty::FreshFloatTy(ct)) => {
174180
if ct >= self.ty_freshen_count {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
637637
self.in_snapshot.get()
638638
}
639639

640-
pub fn freshen<T: TypeFoldable<'tcx>>(&self, t: T) -> T {
640+
pub fn freshen<T: TypeFoldable<'tcx>>(&mut self, t: T) -> T {
641641
t.fold_with(&mut self.freshener())
642642
}
643643

@@ -648,7 +648,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
648648
}
649649
}
650650

651-
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {
651+
pub fn freshener<'b>(&'b mut self) -> TypeFreshener<'b, 'a, 'tcx> {
652652
freshen::TypeFreshener::new(self)
653653
}
654654

0 commit comments

Comments
 (0)