Simplify confusing ResolvedArg constructors
This commit is contained in:
parent
916e9ced40
commit
0b52ec3d7e
1 changed files with 46 additions and 57 deletions
|
@ -33,18 +33,12 @@ use crate::errors;
|
|||
|
||||
#[extension(trait RegionExt)]
|
||||
impl ResolvedArg {
|
||||
fn early(param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
|
||||
debug!("ResolvedArg::early: def_id={:?}", param.def_id);
|
||||
(param.def_id, ResolvedArg::EarlyBound(param.def_id))
|
||||
fn early(param: &GenericParam<'_>) -> ResolvedArg {
|
||||
ResolvedArg::EarlyBound(param.def_id)
|
||||
}
|
||||
|
||||
fn late(idx: u32, param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
|
||||
let depth = ty::INNERMOST;
|
||||
debug!(
|
||||
"ResolvedArg::late: idx={:?}, param={:?} depth={:?} def_id={:?}",
|
||||
idx, param, depth, param.def_id,
|
||||
);
|
||||
(param.def_id, ResolvedArg::LateBound(depth, idx, param.def_id))
|
||||
fn late(idx: u32, param: &GenericParam<'_>) -> ResolvedArg {
|
||||
ResolvedArg::LateBound(ty::INNERMOST, idx, param.def_id)
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<LocalDefId> {
|
||||
|
@ -282,12 +276,9 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
|
|||
|
||||
fn late_arg_as_bound_arg<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
arg: &ResolvedArg,
|
||||
param: &GenericParam<'tcx>,
|
||||
) -> ty::BoundVariableKind {
|
||||
match arg {
|
||||
ResolvedArg::LateBound(_, _, def_id) => {
|
||||
let def_id = def_id.to_def_id();
|
||||
let def_id = param.def_id.to_def_id();
|
||||
let name = tcx.item_name(def_id);
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
|
@ -299,9 +290,6 @@ fn late_arg_as_bound_arg<'tcx>(
|
|||
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
|
||||
}
|
||||
}
|
||||
_ => bug!("{:?} is not a late argument", arg),
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
/// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
|
||||
|
@ -360,10 +348,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
let mut bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = FxIndexMap::default();
|
||||
let binders_iter =
|
||||
trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
|
||||
let pair = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
|
||||
let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
|
||||
bound_vars.insert(pair.0, pair.1);
|
||||
r
|
||||
let arg = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
|
||||
bound_vars.insert(param.def_id, arg);
|
||||
late_arg_as_bound_arg(self.tcx, param)
|
||||
});
|
||||
binders.extend(binders_iter);
|
||||
|
||||
|
@ -458,9 +445,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(late_bound_idx, param)| {
|
||||
let pair = ResolvedArg::late(late_bound_idx as u32, param);
|
||||
let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
|
||||
(pair, r)
|
||||
(
|
||||
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
|
||||
late_arg_as_bound_arg(self.tcx, param),
|
||||
)
|
||||
})
|
||||
.unzip();
|
||||
|
||||
|
@ -492,8 +480,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
let mut bound_vars = FxIndexMap::default();
|
||||
debug!(?opaque.generics.params);
|
||||
for param in opaque.generics.params {
|
||||
let (def_id, reg) = ResolvedArg::early(param);
|
||||
bound_vars.insert(def_id, reg);
|
||||
let arg = ResolvedArg::early(param);
|
||||
bound_vars.insert(param.def_id, arg);
|
||||
}
|
||||
|
||||
let hir_id = self.tcx.local_def_id_to_hir_id(opaque.def_id);
|
||||
|
@ -618,9 +606,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(late_bound_idx, param)| {
|
||||
let pair = ResolvedArg::late(late_bound_idx as u32, param);
|
||||
let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
|
||||
(pair, r)
|
||||
(
|
||||
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
|
||||
late_arg_as_bound_arg(self.tcx, param),
|
||||
)
|
||||
})
|
||||
.unzip();
|
||||
|
||||
|
@ -870,9 +859,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(late_bound_idx, param)| {
|
||||
let pair = ResolvedArg::late(late_bound_idx as u32, param);
|
||||
let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
|
||||
(pair, r)
|
||||
(
|
||||
(param.def_id, ResolvedArg::late(late_bound_idx as u32, param)),
|
||||
late_arg_as_bound_arg(self.tcx, param),
|
||||
)
|
||||
})
|
||||
.unzip();
|
||||
|
||||
|
@ -1052,7 +1042,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
let bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = generics
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| match param.kind {
|
||||
.map(|param| {
|
||||
(param.def_id, match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
if self.tcx.is_late_bound(param.hir_id) {
|
||||
let late_bound_idx = named_late_bound_vars;
|
||||
|
@ -1066,6 +1057,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
ResolvedArg::early(param)
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
let binders: Vec<_> = generics
|
||||
|
@ -1075,11 +1067,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
matches!(param.kind, GenericParamKind::Lifetime { .. })
|
||||
&& self.tcx.is_late_bound(param.hir_id)
|
||||
})
|
||||
.enumerate()
|
||||
.map(|(late_bound_idx, param)| {
|
||||
let pair = ResolvedArg::late(late_bound_idx as u32, param);
|
||||
late_arg_as_bound_arg(self.tcx, &pair.1, param)
|
||||
})
|
||||
.map(|param| late_arg_as_bound_arg(self.tcx, param))
|
||||
.collect();
|
||||
self.record_late_bound_vars(hir_id, binders);
|
||||
let scope = Scope::Binder {
|
||||
|
@ -1096,7 +1084,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
where
|
||||
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
|
||||
{
|
||||
let bound_vars = generics.params.iter().map(ResolvedArg::early).collect();
|
||||
let bound_vars =
|
||||
generics.params.iter().map(|param| (param.def_id, ResolvedArg::early(param))).collect();
|
||||
self.record_late_bound_vars(hir_id, vec![]);
|
||||
let scope = Scope::Binder {
|
||||
hir_id,
|
||||
|
|
Loading…
Add table
Reference in a new issue