reviews ish
This commit is contained in:
parent
b3d71d9001
commit
61c07a9a23
3 changed files with 19 additions and 6 deletions
|
@ -314,6 +314,13 @@ impl GenericArg<'_> {
|
|||
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_ty_or_const(&self) -> bool {
|
||||
match self {
|
||||
GenericArg::Lifetime(_) => false,
|
||||
GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
|
|
|
@ -31,6 +31,13 @@ impl GenericParamDefKind {
|
|||
GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_ty_or_const(&self) -> bool {
|
||||
match self {
|
||||
GenericParamDefKind::Lifetime => false,
|
||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
|
|
|
@ -80,7 +80,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
.and_then(|args| {
|
||||
args.args
|
||||
.iter()
|
||||
.filter(|arg| !matches!(arg, GenericArg::Lifetime(_)))
|
||||
.filter(|arg| arg.is_ty_or_const())
|
||||
.position(|arg| arg.id() == hir_id)
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
|
@ -113,7 +113,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
.and_then(|args| {
|
||||
args.args
|
||||
.iter()
|
||||
.filter(|arg| !matches!(arg, GenericArg::Lifetime(_)))
|
||||
.filter(|arg| arg.is_ty_or_const())
|
||||
.position(|arg| arg.id() == hir_id)
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
|
@ -169,7 +169,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
.filter_map(|seg| seg.args.map(|args| (args.args, seg)))
|
||||
.find_map(|(args, seg)| {
|
||||
args.iter()
|
||||
.filter(|arg| !matches!(arg, GenericArg::Lifetime(_)))
|
||||
.filter(|arg| arg.is_ty_or_const())
|
||||
.position(|arg| arg.id() == hir_id)
|
||||
.map(|index| (index, seg))
|
||||
});
|
||||
|
@ -232,12 +232,11 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
};
|
||||
|
||||
debug!(?parent_node);
|
||||
debug!(?generics);
|
||||
debug!(?arg_idx);
|
||||
debug!(?generics, ?arg_idx);
|
||||
generics
|
||||
.params
|
||||
.iter()
|
||||
.filter(|param| !matches!(param.kind, ty::GenericParamDefKind::Lifetime { .. }))
|
||||
.filter(|param| param.kind.is_ty_or_const())
|
||||
.nth(match generics.has_self && generics.parent.is_none() {
|
||||
true => arg_idx + 1,
|
||||
false => arg_idx,
|
||||
|
|
Loading…
Add table
Reference in a new issue