Put a ShallowResolver
within OpportunisticVarResolver
.
So one doesn't have to be constructed every time.
This commit is contained in:
parent
a676496750
commit
bac7628eae
1 changed files with 7 additions and 5 deletions
|
@ -16,26 +16,28 @@ use std::ops::ControlFlow;
|
||||||
/// useful for printing messages etc but also required at various
|
/// useful for printing messages etc but also required at various
|
||||||
/// points for correctness.
|
/// points for correctness.
|
||||||
pub struct OpportunisticVarResolver<'a, 'tcx> {
|
pub struct OpportunisticVarResolver<'a, 'tcx> {
|
||||||
infcx: &'a InferCtxt<'tcx>,
|
// The shallow resolver is used to resolve inference variables at every
|
||||||
|
// level of the type.
|
||||||
|
shallow_resolver: crate::infer::ShallowResolver<'a, 'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> {
|
impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(infcx: &'a InferCtxt<'tcx>) -> Self {
|
pub fn new(infcx: &'a InferCtxt<'tcx>) -> Self {
|
||||||
OpportunisticVarResolver { infcx }
|
OpportunisticVarResolver { shallow_resolver: crate::infer::ShallowResolver { infcx } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
|
impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
|
||||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||||
self.infcx.tcx
|
TypeFolder::tcx(&self.shallow_resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if !t.has_non_region_infer() {
|
if !t.has_non_region_infer() {
|
||||||
t // micro-optimize -- if there is nothing in this type that this fold affects...
|
t // micro-optimize -- if there is nothing in this type that this fold affects...
|
||||||
} else {
|
} else {
|
||||||
let t = self.infcx.shallow_resolve(t);
|
let t = self.shallow_resolver.fold_ty(t);
|
||||||
t.super_fold_with(self)
|
t.super_fold_with(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +46,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
|
||||||
if !ct.has_non_region_infer() {
|
if !ct.has_non_region_infer() {
|
||||||
ct // micro-optimize -- if there is nothing in this const that this fold affects...
|
ct // micro-optimize -- if there is nothing in this const that this fold affects...
|
||||||
} else {
|
} else {
|
||||||
let ct = self.infcx.shallow_resolve(ct);
|
let ct = self.shallow_resolver.fold_const(ct);
|
||||||
ct.super_fold_with(self)
|
ct.super_fold_with(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue