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
|
@ -7,7 +7,7 @@
|
||||||
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
|
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
|
||||||
|
|
||||||
use crate::infer::canonical::{Canonical, CanonicalVarValues};
|
use crate::infer::canonical::{Canonical, CanonicalVarValues};
|
||||||
use rustc_middle::ty::fold::TypeFoldable;
|
use rustc_middle::ty::fold::{FnMutDelegate, TypeFoldable};
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
|
||||||
|
@ -71,21 +71,21 @@ where
|
||||||
if var_values.var_values.is_empty() {
|
if var_values.var_values.is_empty() {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let fld_r = |br: ty::BoundRegion| match var_values.var_values[br.var].unpack() {
|
let delegate = FnMutDelegate {
|
||||||
GenericArgKind::Lifetime(l) => l,
|
regions: |br: ty::BoundRegion| match var_values.var_values[br.var].unpack() {
|
||||||
r => bug!("{:?} is a region but value is {:?}", br, r),
|
GenericArgKind::Lifetime(l) => l,
|
||||||
|
r => bug!("{:?} is a region but value is {:?}", br, r),
|
||||||
|
},
|
||||||
|
types: |bound_ty: ty::BoundTy| match var_values.var_values[bound_ty.var].unpack() {
|
||||||
|
GenericArgKind::Type(ty) => ty,
|
||||||
|
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
|
||||||
|
},
|
||||||
|
consts: |bound_ct: ty::BoundVar, _| match var_values.var_values[bound_ct].unpack() {
|
||||||
|
GenericArgKind::Const(ct) => ct,
|
||||||
|
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let fld_t = |bound_ty: ty::BoundTy| match var_values.var_values[bound_ty.var].unpack() {
|
tcx.replace_escaping_bound_vars_uncached(value, delegate)
|
||||||
GenericArgKind::Type(ty) => ty,
|
|
||||||
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
|
|
||||||
};
|
|
||||||
|
|
||||||
let fld_c = |bound_ct: ty::BoundVar, _| match var_values.var_values[bound_ct].unpack() {
|
|
||||||
GenericArgKind::Const(ct) => ct,
|
|
||||||
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
|
|
||||||
};
|
|
||||||
|
|
||||||
tcx.replace_escaping_bound_vars_uncached(value, fld_r, fld_t, fld_c)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
use super::combine::CombineFields;
|
use super::combine::CombineFields;
|
||||||
use super::{HigherRankedType, InferCtxt};
|
use super::{HigherRankedType, InferCtxt};
|
||||||
use crate::infer::CombinedSnapshot;
|
use crate::infer::CombinedSnapshot;
|
||||||
|
use rustc_middle::ty::fold::FnMutDelegate;
|
||||||
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||||
use rustc_middle::ty::{self, Binder, TypeFoldable};
|
use rustc_middle::ty::{self, Binder, TypeFoldable};
|
||||||
|
|
||||||
|
@ -79,31 +80,31 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
let next_universe = self.create_next_universe();
|
let next_universe = self.create_next_universe();
|
||||||
|
|
||||||
let fld_r = |br: ty::BoundRegion| {
|
let delegate = FnMutDelegate {
|
||||||
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
|
regions: |br: ty::BoundRegion| {
|
||||||
universe: next_universe,
|
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
|
||||||
name: br.kind,
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
|
|
||||||
let fld_t = |bound_ty: ty::BoundTy| {
|
|
||||||
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
|
||||||
universe: next_universe,
|
|
||||||
name: bound_ty.var,
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
|
|
||||||
let fld_c = |bound_var: ty::BoundVar, ty| {
|
|
||||||
self.tcx.mk_const(ty::ConstS {
|
|
||||||
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
name: ty::BoundConst { var: bound_var, ty },
|
name: br.kind,
|
||||||
}),
|
}))
|
||||||
ty,
|
},
|
||||||
})
|
types: |bound_ty: ty::BoundTy| {
|
||||||
|
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
||||||
|
universe: next_universe,
|
||||||
|
name: bound_ty.var,
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
consts: |bound_var: ty::BoundVar, ty| {
|
||||||
|
self.tcx.mk_const(ty::ConstS {
|
||||||
|
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
|
||||||
|
universe: next_universe,
|
||||||
|
name: ty::BoundConst { var: bound_var, ty },
|
||||||
|
}),
|
||||||
|
ty,
|
||||||
|
})
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = self.tcx.replace_bound_vars_uncached(binder, fld_r, fld_t, fld_c);
|
let result = self.tcx.replace_bound_vars_uncached(binder, delegate);
|
||||||
debug!(?next_universe, ?result);
|
debug!(?next_universe, ?result);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
|
||||||
use rustc_middle::traits::select;
|
use rustc_middle::traits::select;
|
||||||
use rustc_middle::ty::abstract_const::{AbstractConst, FailureKind};
|
use rustc_middle::ty::abstract_const::{AbstractConst, FailureKind};
|
||||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
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::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
use rustc_middle::ty::relate::RelateResult;
|
use rustc_middle::ty::relate::RelateResult;
|
||||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
|
||||||
|
@ -1564,32 +1565,56 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
return inner;
|
return inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut region_map = FxHashMap::default();
|
struct ToFreshVars<'a, 'tcx> {
|
||||||
let fld_r = |br: ty::BoundRegion| {
|
infcx: &'a InferCtxt<'a, 'tcx>,
|
||||||
*region_map
|
span: Span,
|
||||||
.entry(br)
|
lbrct: LateBoundRegionConversionTime,
|
||||||
.or_insert_with(|| self.next_region_var(LateBoundRegion(span, br.kind, lbrct)))
|
map: FxHashMap<ty::BoundVar, ty::GenericArg<'tcx>>,
|
||||||
};
|
}
|
||||||
|
|
||||||
let mut ty_map = FxHashMap::default();
|
impl<'tcx> BoundVarReplacerDelegate<'tcx> for ToFreshVars<'_, 'tcx> {
|
||||||
let fld_t = |bt: ty::BoundTy| {
|
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
|
||||||
*ty_map.entry(bt).or_insert_with(|| {
|
self.map
|
||||||
self.next_ty_var(TypeVariableOrigin {
|
.entry(br.var)
|
||||||
kind: TypeVariableOriginKind::MiscVariable,
|
.or_insert_with(|| {
|
||||||
span,
|
self.infcx
|
||||||
})
|
.next_region_var(LateBoundRegion(self.span, br.kind, self.lbrct))
|
||||||
})
|
.into()
|
||||||
};
|
})
|
||||||
let mut ct_map = FxHashMap::default();
|
.expect_region()
|
||||||
let fld_c = |bc: ty::BoundVar, ty| {
|
}
|
||||||
*ct_map.entry(bc).or_insert_with(|| {
|
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
||||||
self.next_const_var(
|
self.map
|
||||||
ty,
|
.entry(bt.var)
|
||||||
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span },
|
.or_insert_with(|| {
|
||||||
)
|
self.infcx
|
||||||
})
|
.next_ty_var(TypeVariableOrigin {
|
||||||
};
|
kind: TypeVariableOriginKind::MiscVariable,
|
||||||
self.tcx.replace_bound_vars_uncached(value, fld_r, fld_t, fld_c)
|
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.
|
/// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method.
|
||||||
|
|
|
@ -370,6 +370,34 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Bound vars replacer
|
// Bound vars replacer
|
||||||
|
|
||||||
|
pub trait BoundVarReplacerDelegate<'tcx> {
|
||||||
|
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx>;
|
||||||
|
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx>;
|
||||||
|
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FnMutDelegate<R, T, C> {
|
||||||
|
pub regions: R,
|
||||||
|
pub types: T,
|
||||||
|
pub consts: C,
|
||||||
|
}
|
||||||
|
impl<'tcx, R, T, C> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<R, T, C>
|
||||||
|
where
|
||||||
|
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> {
|
||||||
|
(self.regions)(br)
|
||||||
|
}
|
||||||
|
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
||||||
|
(self.types)(bt)
|
||||||
|
}
|
||||||
|
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||||
|
(self.consts)(bv, ty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Replaces the escaping bound vars (late bound regions or bound types) in a type.
|
/// Replaces the escaping bound vars (late bound regions or bound types) in a type.
|
||||||
struct BoundVarReplacer<'a, 'tcx> {
|
struct BoundVarReplacer<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
@ -378,19 +406,12 @@ struct BoundVarReplacer<'a, 'tcx> {
|
||||||
/// the ones we have visited.
|
/// the ones we have visited.
|
||||||
current_index: ty::DebruijnIndex,
|
current_index: ty::DebruijnIndex,
|
||||||
|
|
||||||
fld_r: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
|
delegate: &'a mut dyn BoundVarReplacerDelegate<'tcx>,
|
||||||
fld_t: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
|
|
||||||
fld_c: &'a mut (dyn FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx> + 'a),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> BoundVarReplacer<'a, 'tcx> {
|
impl<'a, 'tcx> BoundVarReplacer<'a, 'tcx> {
|
||||||
fn new(
|
fn new(tcx: TyCtxt<'tcx>, delegate: &'a mut dyn BoundVarReplacerDelegate<'tcx>) -> Self {
|
||||||
tcx: TyCtxt<'tcx>,
|
BoundVarReplacer { tcx, current_index: ty::INNERMOST, delegate }
|
||||||
fld_r: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
|
|
||||||
fld_t: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
|
|
||||||
fld_c: &'a mut (dyn FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx> + 'a),
|
|
||||||
) -> Self {
|
|
||||||
BoundVarReplacer { tcx, current_index: ty::INNERMOST, fld_r, fld_t, fld_c }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +433,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
|
||||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
match *t.kind() {
|
match *t.kind() {
|
||||||
ty::Bound(debruijn, bound_ty) if debruijn == self.current_index => {
|
ty::Bound(debruijn, bound_ty) if debruijn == self.current_index => {
|
||||||
let ty = (self.fld_t)(bound_ty);
|
let ty = self.delegate.replace_ty(bound_ty);
|
||||||
ty::fold::shift_vars(self.tcx, ty, self.current_index.as_u32())
|
ty::fold::shift_vars(self.tcx, ty, self.current_index.as_u32())
|
||||||
}
|
}
|
||||||
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
|
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
|
||||||
|
@ -423,7 +444,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
|
||||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
match *r {
|
match *r {
|
||||||
ty::ReLateBound(debruijn, br) if debruijn == self.current_index => {
|
ty::ReLateBound(debruijn, br) if debruijn == self.current_index => {
|
||||||
let region = (self.fld_r)(br);
|
let region = self.delegate.replace_region(br);
|
||||||
if let ty::ReLateBound(debruijn1, br) = *region {
|
if let ty::ReLateBound(debruijn1, br) = *region {
|
||||||
// If the callback returns a late-bound region,
|
// If the callback returns a late-bound region,
|
||||||
// that region should always use the INNERMOST
|
// that region should always use the INNERMOST
|
||||||
|
@ -442,7 +463,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
|
||||||
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
||||||
match ct.kind() {
|
match ct.kind() {
|
||||||
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => {
|
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => {
|
||||||
let ct = (self.fld_c)(bound_const, ct.ty());
|
let ct = self.delegate.replace_const(bound_const, ct.ty());
|
||||||
ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32())
|
ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32())
|
||||||
}
|
}
|
||||||
_ => ct.super_fold_with(self),
|
_ => ct.super_fold_with(self),
|
||||||
|
@ -486,19 +507,22 @@ 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>,
|
||||||
mut fld_r: F,
|
replace_regions: F,
|
||||||
) -> T
|
) -> T
|
||||||
where
|
where
|
||||||
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
||||||
T: TypeFoldable<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
let mut fld_t = |b| bug!("unexpected bound ty in binder: {b:?}");
|
|
||||||
let mut fld_c = |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}");
|
|
||||||
let value = value.skip_binder();
|
let value = value.skip_binder();
|
||||||
if !value.has_escaping_bound_vars() {
|
if !value.has_escaping_bound_vars() {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let mut replacer = BoundVarReplacer::new(self, &mut fld_r, &mut fld_t, &mut fld_c);
|
let mut delegate = FnMutDelegate {
|
||||||
|
regions: replace_regions,
|
||||||
|
types: |b| bug!("unexpected bound ty in binder: {b:?}"),
|
||||||
|
consts: |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
|
||||||
|
};
|
||||||
|
let mut replacer = BoundVarReplacer::new(self, &mut delegate);
|
||||||
value.fold_with(&mut replacer)
|
value.fold_with(&mut replacer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -506,23 +530,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
|
/// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
|
||||||
/// bound regions; the `fld_t` closure replaces escaping bound types and the `fld_c`
|
/// bound regions; the `fld_t` closure replaces escaping bound types and the `fld_c`
|
||||||
/// closure replaces escaping bound consts.
|
/// closure replaces escaping bound consts.
|
||||||
pub fn replace_escaping_bound_vars_uncached<T, F, G, H>(
|
pub fn replace_escaping_bound_vars_uncached<T: TypeFoldable<'tcx>>(
|
||||||
self,
|
self,
|
||||||
value: T,
|
value: T,
|
||||||
mut fld_r: F,
|
mut delegate: impl BoundVarReplacerDelegate<'tcx>,
|
||||||
mut fld_t: G,
|
) -> T {
|
||||||
mut fld_c: H,
|
|
||||||
) -> T
|
|
||||||
where
|
|
||||||
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
|
||||||
G: FnMut(ty::BoundTy) -> Ty<'tcx>,
|
|
||||||
H: FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx>,
|
|
||||||
T: TypeFoldable<'tcx>,
|
|
||||||
{
|
|
||||||
if !value.has_escaping_bound_vars() {
|
if !value.has_escaping_bound_vars() {
|
||||||
value
|
value
|
||||||
} else {
|
} else {
|
||||||
let mut replacer = BoundVarReplacer::new(self, &mut fld_r, &mut fld_t, &mut fld_c);
|
let mut replacer = BoundVarReplacer::new(self, &mut delegate);
|
||||||
value.fold_with(&mut replacer)
|
value.fold_with(&mut replacer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,20 +546,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Replaces all types or regions bound by the given `Binder`. The `fld_r`
|
/// Replaces all types or regions bound by the given `Binder`. The `fld_r`
|
||||||
/// closure replaces bound regions, the `fld_t` closure replaces bound
|
/// closure replaces bound regions, the `fld_t` closure replaces bound
|
||||||
/// types, and `fld_c` replaces bound constants.
|
/// types, and `fld_c` replaces bound constants.
|
||||||
pub fn replace_bound_vars_uncached<T, F, G, H>(
|
pub fn replace_bound_vars_uncached<T: TypeFoldable<'tcx>>(
|
||||||
self,
|
self,
|
||||||
value: Binder<'tcx, T>,
|
value: Binder<'tcx, T>,
|
||||||
fld_r: F,
|
delegate: impl BoundVarReplacerDelegate<'tcx>,
|
||||||
fld_t: G,
|
) -> T {
|
||||||
fld_c: H,
|
self.replace_escaping_bound_vars_uncached(value.skip_binder(), delegate)
|
||||||
) -> T
|
|
||||||
where
|
|
||||||
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
|
|
||||||
G: FnMut(ty::BoundTy) -> Ty<'tcx>,
|
|
||||||
H: FnMut(ty::BoundVar, Ty<'tcx>) -> ty::Const<'tcx>,
|
|
||||||
T: TypeFoldable<'tcx>,
|
|
||||||
{
|
|
||||||
self.replace_escaping_bound_vars_uncached(value.skip_binder(), fld_r, fld_t, fld_c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces any late-bound regions bound in `value` with
|
/// Replaces any late-bound regions bound in `value` with
|
||||||
|
@ -568,34 +576,28 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
where
|
where
|
||||||
T: TypeFoldable<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
|
let shift_bv = |bv: ty::BoundVar| ty::BoundVar::from_usize(bv.as_usize() + bound_vars);
|
||||||
self.replace_escaping_bound_vars_uncached(
|
self.replace_escaping_bound_vars_uncached(
|
||||||
value,
|
value,
|
||||||
|r| {
|
FnMutDelegate {
|
||||||
self.mk_region(ty::ReLateBound(
|
regions: |r: ty::BoundRegion| {
|
||||||
ty::INNERMOST,
|
self.mk_region(ty::ReLateBound(
|
||||||
ty::BoundRegion {
|
|
||||||
var: ty::BoundVar::from_usize(r.var.as_usize() + bound_vars),
|
|
||||||
kind: r.kind,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
},
|
|
||||||
|t| {
|
|
||||||
self.mk_ty(ty::Bound(
|
|
||||||
ty::INNERMOST,
|
|
||||||
ty::BoundTy {
|
|
||||||
var: ty::BoundVar::from_usize(t.var.as_usize() + bound_vars),
|
|
||||||
kind: t.kind,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
},
|
|
||||||
|c, ty| {
|
|
||||||
self.mk_const(ty::ConstS {
|
|
||||||
kind: ty::ConstKind::Bound(
|
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundVar::from_usize(c.as_usize() + bound_vars),
|
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
|
||||||
),
|
))
|
||||||
ty,
|
},
|
||||||
})
|
types: |t: ty::BoundTy| {
|
||||||
|
self.mk_ty(ty::Bound(
|
||||||
|
ty::INNERMOST,
|
||||||
|
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
|
||||||
|
))
|
||||||
|
},
|
||||||
|
consts: |c, ty: Ty<'tcx>| {
|
||||||
|
self.mk_const(ty::ConstS {
|
||||||
|
kind: ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)),
|
||||||
|
ty,
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,14 @@ impl<'tcx> GenericArg<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Unpack the `GenericArg` as a region when it is known certainly to be a region.
|
||||||
|
pub fn expect_region(self) -> ty::Region<'tcx> {
|
||||||
|
match self.unpack() {
|
||||||
|
GenericArgKind::Lifetime(lt) => lt,
|
||||||
|
_ => bug!("expected a region, but found another kind"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Unpack the `GenericArg` as a type when it is known certainly to be a type.
|
/// Unpack the `GenericArg` as a type when it is known certainly to be a type.
|
||||||
/// This is true in cases where `Substs` is used in places where the kinds are known
|
/// This is true in cases where `Substs` is used in places where the kinds are known
|
||||||
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
|
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue