Skip to content

Commit

Permalink
reviews ish
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Jan 14, 2022
1 parent b3d71d9 commit 61c07a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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))
});
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 61c07a9

Please sign in to comment.