summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/clippy_lints/src/types/utils.rs
blob: 7f43b7841ff33d887668c2b321e686db081d9d76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use clippy_utils::last_path_segment;
use if_chain::if_chain;
use rustc_hir::{GenericArg, QPath, TyKind};
use rustc_lint::LateContext;
use rustc_span::source_map::Span;

pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<Span> {
    let last = last_path_segment(qpath);
    if_chain! {
        if let Some(params) = last.args;
        if !params.parenthesized;
        if let Some(ty) = params.args.iter().find_map(|arg| match arg {
            GenericArg::Type(ty) => Some(ty),
            _ => None,
        });
        if let TyKind::Ref(..) = ty.kind;
        then {
            return Some(ty.span);
        }
    }
    None
}