change FnMutDelegate
to trait objects
This commit is contained in:
parent
294f0eef73
commit
5669ce1a28
3 changed files with 20 additions and 23 deletions
|
@ -72,15 +72,16 @@ where
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let delegate = FnMutDelegate {
|
let delegate = FnMutDelegate {
|
||||||
regions: |br: ty::BoundRegion| match var_values.var_values[br.var].unpack() {
|
regions: &mut |br: ty::BoundRegion| match var_values.var_values[br.var].unpack() {
|
||||||
GenericArgKind::Lifetime(l) => l,
|
GenericArgKind::Lifetime(l) => l,
|
||||||
r => bug!("{:?} is a region but value is {:?}", br, r),
|
r => bug!("{:?} is a region but value is {:?}", br, r),
|
||||||
},
|
},
|
||||||
types: |bound_ty: ty::BoundTy| match var_values.var_values[bound_ty.var].unpack() {
|
types: &mut |bound_ty: ty::BoundTy| match var_values.var_values[bound_ty.var].unpack() {
|
||||||
GenericArgKind::Type(ty) => ty,
|
GenericArgKind::Type(ty) => ty,
|
||||||
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
|
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
|
||||||
},
|
},
|
||||||
consts: |bound_ct: ty::BoundVar, _| match var_values.var_values[bound_ct].unpack() {
|
consts: &mut |bound_ct: ty::BoundVar, _| match var_values.var_values[bound_ct].unpack()
|
||||||
|
{
|
||||||
GenericArgKind::Const(ct) => ct,
|
GenericArgKind::Const(ct) => ct,
|
||||||
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
|
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
|
||||||
},
|
},
|
||||||
|
|
|
@ -81,19 +81,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
let next_universe = self.create_next_universe();
|
let next_universe = self.create_next_universe();
|
||||||
|
|
||||||
let delegate = FnMutDelegate {
|
let delegate = FnMutDelegate {
|
||||||
regions: |br: ty::BoundRegion| {
|
regions: &mut |br: ty::BoundRegion| {
|
||||||
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
|
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
name: br.kind,
|
name: br.kind,
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
types: |bound_ty: ty::BoundTy| {
|
types: &mut |bound_ty: ty::BoundTy| {
|
||||||
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
name: bound_ty.var,
|
name: bound_ty.var,
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
consts: |bound_var: ty::BoundVar, ty| {
|
consts: &mut |bound_var: ty::BoundVar, ty| {
|
||||||
self.tcx.mk_const(ty::ConstS {
|
self.tcx.mk_const(ty::ConstS {
|
||||||
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
|
|
|
@ -377,17 +377,13 @@ pub trait BoundVarReplacerDelegate<'tcx> {
|
||||||
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx>;
|
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FnMutDelegate<R, T, C> {
|
pub struct FnMutDelegate<'a, 'tcx> {
|
||||||
pub regions: R,
|
pub regions: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
|
||||||
pub types: T,
|
pub types: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
|
||||||
pub consts: C,
|
pub consts: &'a mut (dyn FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx> + 'a),
|
||||||
}
|
}
|
||||||
impl<'tcx, R, T, C> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<R, T, C>
|
|
||||||
where
|
impl<'a, 'tcx> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<'a, 'tcx> {
|
||||||
R: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
|
||||||
T: FnMut(ty::BoundTy) -> Ty<'tcx>,
|
|
||||||
C: FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx>,
|
|
||||||
{
|
|
||||||
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
|
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
|
||||||
(self.regions)(br)
|
(self.regions)(br)
|
||||||
}
|
}
|
||||||
|
@ -511,7 +507,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn replace_late_bound_regions_uncached<T, F>(
|
pub fn replace_late_bound_regions_uncached<T, F>(
|
||||||
self,
|
self,
|
||||||
value: Binder<'tcx, T>,
|
value: Binder<'tcx, T>,
|
||||||
replace_regions: F,
|
mut replace_regions: F,
|
||||||
) -> T
|
) -> T
|
||||||
where
|
where
|
||||||
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
||||||
|
@ -522,9 +518,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let delegate = FnMutDelegate {
|
let delegate = FnMutDelegate {
|
||||||
regions: replace_regions,
|
regions: &mut replace_regions,
|
||||||
types: |b| bug!("unexpected bound ty in binder: {b:?}"),
|
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
|
||||||
consts: |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
|
consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
|
||||||
};
|
};
|
||||||
let mut replacer = BoundVarReplacer::new(self, delegate);
|
let mut replacer = BoundVarReplacer::new(self, delegate);
|
||||||
value.fold_with(&mut replacer)
|
value.fold_with(&mut replacer)
|
||||||
|
@ -584,19 +580,19 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.replace_escaping_bound_vars_uncached(
|
self.replace_escaping_bound_vars_uncached(
|
||||||
value,
|
value,
|
||||||
FnMutDelegate {
|
FnMutDelegate {
|
||||||
regions: |r: ty::BoundRegion| {
|
regions: &mut |r: ty::BoundRegion| {
|
||||||
self.mk_region(ty::ReLateBound(
|
self.mk_region(ty::ReLateBound(
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
|
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
types: |t: ty::BoundTy| {
|
types: &mut |t: ty::BoundTy| {
|
||||||
self.mk_ty(ty::Bound(
|
self.mk_ty(ty::Bound(
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
|
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
consts: |c, ty: Ty<'tcx>| {
|
consts: &mut |c, ty: Ty<'tcx>| {
|
||||||
self.mk_const(ty::ConstS {
|
self.mk_const(ty::ConstS {
|
||||||
kind: ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)),
|
kind: ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)),
|
||||||
ty,
|
ty,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue