Skip to content

Commit 145d7fc

Browse files
committed
Factor out get_qpath_generics
1 parent 20781f1 commit 145d7fc

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

clippy_utils/src/lib.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
7777
use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk};
7878
use rustc_hir::{
7979
def, lang_items, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr,
80-
ExprKind, FnDecl, ForeignItem, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem,
81-
Local, MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind,
82-
Target, TraitItem, TraitItemKind, TraitRef, TyKind, UnOp,
80+
ExprKind, FnDecl, ForeignItem, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local,
81+
MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Target,
82+
TraitItem, TraitItemKind, TraitRef, TyKind, UnOp,
8383
};
8484
use rustc_lint::{LateContext, Level, Lint, LintContext};
8585
use rustc_middle::hir::place::PlaceBase;
@@ -360,24 +360,14 @@ pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> {
360360
}
361361
}
362362

363-
pub fn get_qpath_generics<'tcx>(path: &QPath<'tcx>) -> Option<&'tcx GenericArgs<'tcx>> {
364-
match path {
365-
QPath::Resolved(_, p) => p.segments.last().and_then(|s| s.args),
366-
QPath::TypeRelative(_, s) => s.args,
367-
QPath::LangItem(..) => None,
368-
}
369-
}
370-
371-
pub fn qpath_generic_tys<'tcx>(path: &QPath<'tcx>) -> impl Iterator<Item = &'tcx hir::Ty<'tcx>> {
372-
get_qpath_generics(path)
373-
.map_or([].as_ref(), |a| a.args)
363+
pub fn qpath_generic_tys<'tcx>(qpath: &QPath<'tcx>) -> impl Iterator<Item = &'tcx hir::Ty<'tcx>> {
364+
last_path_segment(qpath)
365+
.args
366+
.map_or(&[][..], |a| a.args)
374367
.iter()
375-
.filter_map(|a| {
376-
if let hir::GenericArg::Type(ty) = a {
377-
Some(ty)
378-
} else {
379-
None
380-
}
368+
.filter_map(|a| match a {
369+
hir::GenericArg::Type(ty) => Some(ty),
370+
_ => None,
381371
})
382372
}
383373

0 commit comments

Comments
 (0)