BoundVarReplacer
: trait object instead of 3 fns
This commit is contained in:
parent
05e678ccca
commit
fd59d058ec
5 changed files with 164 additions and 128 deletions
|
@ -23,6 +23,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
|
|||
use rustc_middle::traits::select;
|
||||
use rustc_middle::ty::abstract_const::{AbstractConst, FailureKind};
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::fold::BoundVarReplacerDelegate;
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||
use rustc_middle::ty::relate::RelateResult;
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
|
||||
|
@ -1564,32 +1565,56 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
return inner;
|
||||
}
|
||||
|
||||
let mut region_map = FxHashMap::default();
|
||||
let fld_r = |br: ty::BoundRegion| {
|
||||
*region_map
|
||||
.entry(br)
|
||||
.or_insert_with(|| self.next_region_var(LateBoundRegion(span, br.kind, lbrct)))
|
||||
};
|
||||
struct ToFreshVars<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'a, 'tcx>,
|
||||
span: Span,
|
||||
lbrct: LateBoundRegionConversionTime,
|
||||
map: FxHashMap<ty::BoundVar, ty::GenericArg<'tcx>>,
|
||||
}
|
||||
|
||||
let mut ty_map = FxHashMap::default();
|
||||
let fld_t = |bt: ty::BoundTy| {
|
||||
*ty_map.entry(bt).or_insert_with(|| {
|
||||
self.next_ty_var(TypeVariableOrigin {
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
span,
|
||||
})
|
||||
})
|
||||
};
|
||||
let mut ct_map = FxHashMap::default();
|
||||
let fld_c = |bc: ty::BoundVar, ty| {
|
||||
*ct_map.entry(bc).or_insert_with(|| {
|
||||
self.next_const_var(
|
||||
ty,
|
||||
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span },
|
||||
)
|
||||
})
|
||||
};
|
||||
self.tcx.replace_bound_vars_uncached(value, fld_r, fld_t, fld_c)
|
||||
impl<'tcx> BoundVarReplacerDelegate<'tcx> for ToFreshVars<'_, 'tcx> {
|
||||
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
|
||||
self.map
|
||||
.entry(br.var)
|
||||
.or_insert_with(|| {
|
||||
self.infcx
|
||||
.next_region_var(LateBoundRegion(self.span, br.kind, self.lbrct))
|
||||
.into()
|
||||
})
|
||||
.expect_region()
|
||||
}
|
||||
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
||||
self.map
|
||||
.entry(bt.var)
|
||||
.or_insert_with(|| {
|
||||
self.infcx
|
||||
.next_ty_var(TypeVariableOrigin {
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
span: self.span,
|
||||
})
|
||||
.into()
|
||||
})
|
||||
.expect_ty()
|
||||
}
|
||||
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||
self.map
|
||||
.entry(bv)
|
||||
.or_insert_with(|| {
|
||||
self.infcx
|
||||
.next_const_var(
|
||||
ty,
|
||||
ConstVariableOrigin {
|
||||
kind: ConstVariableOriginKind::MiscVariable,
|
||||
span: self.span,
|
||||
},
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.expect_const()
|
||||
}
|
||||
}
|
||||
let delegate = ToFreshVars { infcx: self, span, lbrct, map: Default::default() };
|
||||
self.tcx.replace_bound_vars_uncached(value, delegate)
|
||||
}
|
||||
|
||||
/// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue