Skip to content

Commit bac7628

Browse files
committed
Put a ShallowResolver within OpportunisticVarResolver.
So one doesn't have to be constructed every time.
1 parent a676496 commit bac7628

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/rustc_infer/src/infer/resolve.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@ use std::ops::ControlFlow;
1616
/// useful for printing messages etc but also required at various
1717
/// points for correctness.
1818
pub struct OpportunisticVarResolver<'a, 'tcx> {
19-
infcx: &'a InferCtxt<'tcx>,
19+
// The shallow resolver is used to resolve inference variables at every
20+
// level of the type.
21+
shallow_resolver: crate::infer::ShallowResolver<'a, 'tcx>,
2022
}
2123

2224
impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> {
2325
#[inline]
2426
pub fn new(infcx: &'a InferCtxt<'tcx>) -> Self {
25-
OpportunisticVarResolver { infcx }
27+
OpportunisticVarResolver { shallow_resolver: crate::infer::ShallowResolver { infcx } }
2628
}
2729
}
2830

2931
impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
3032
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
31-
self.infcx.tcx
33+
TypeFolder::tcx(&self.shallow_resolver)
3234
}
3335

3436
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
3537
if !t.has_non_region_infer() {
3638
t // micro-optimize -- if there is nothing in this type that this fold affects...
3739
} else {
38-
let t = self.infcx.shallow_resolve(t);
40+
let t = self.shallow_resolver.fold_ty(t);
3941
t.super_fold_with(self)
4042
}
4143
}
@@ -44,7 +46,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
4446
if !ct.has_non_region_infer() {
4547
ct // micro-optimize -- if there is nothing in this const that this fold affects...
4648
} else {
47-
let ct = self.infcx.shallow_resolve(ct);
49+
let ct = self.shallow_resolver.fold_const(ct);
4850
ct.super_fold_with(self)
4951
}
5052
}

0 commit comments

Comments
 (0)