Skip to content

Commit f3ced4d

Browse files
authored
expect_fun_call: move helper functions out of the main one (#15446)
just a clean-up changelog: none
2 parents e622300 + d5f2b66 commit f3ced4d

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

clippy_lints/src/methods/expect_fun_call.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::ops::ControlFlow;
1515
use super::EXPECT_FUN_CALL;
1616

1717
/// Checks for the `EXPECT_FUN_CALL` lint.
18-
#[allow(clippy::too_many_lines)]
1918
pub(super) fn check<'tcx>(
2019
cx: &LateContext<'tcx>,
2120
format_args_storage: &FormatArgsStorage,
@@ -25,43 +24,6 @@ pub(super) fn check<'tcx>(
2524
receiver: &'tcx hir::Expr<'tcx>,
2625
args: &'tcx [hir::Expr<'tcx>],
2726
) {
28-
// Strip `{}`, `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or
29-
// `&str`
30-
fn get_arg_root<'a>(cx: &LateContext<'_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
31-
let mut arg_root = peel_blocks(arg);
32-
loop {
33-
arg_root = match &arg_root.kind {
34-
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr,
35-
hir::ExprKind::MethodCall(method_name, receiver, [], ..) => {
36-
if (method_name.ident.name == sym::as_str || method_name.ident.name == sym::as_ref) && {
37-
let arg_type = cx.typeck_results().expr_ty(receiver);
38-
let base_type = arg_type.peel_refs();
39-
base_type.is_str() || is_type_lang_item(cx, base_type, hir::LangItem::String)
40-
} {
41-
receiver
42-
} else {
43-
break;
44-
}
45-
},
46-
_ => break,
47-
};
48-
}
49-
arg_root
50-
}
51-
52-
fn contains_call<'a>(cx: &LateContext<'a>, arg: &'a hir::Expr<'a>) -> bool {
53-
for_each_expr(cx, arg, |expr| {
54-
if matches!(expr.kind, hir::ExprKind::MethodCall { .. } | hir::ExprKind::Call { .. })
55-
&& !is_inside_always_const_context(cx.tcx, expr.hir_id)
56-
{
57-
ControlFlow::Break(())
58-
} else {
59-
ControlFlow::Continue(())
60-
}
61-
})
62-
.is_some()
63-
}
64-
6527
if name == sym::expect
6628
&& let [arg] = args
6729
&& let arg_root = get_arg_root(cx, arg)
@@ -114,3 +76,40 @@ pub(super) fn check<'tcx>(
11476
);
11577
}
11678
}
79+
80+
/// Strip `{}`, `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or
81+
/// `&str`
82+
fn get_arg_root<'a>(cx: &LateContext<'_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
83+
let mut arg_root = peel_blocks(arg);
84+
loop {
85+
arg_root = match &arg_root.kind {
86+
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => expr,
87+
hir::ExprKind::MethodCall(method_name, receiver, [], ..) => {
88+
if (method_name.ident.name == sym::as_str || method_name.ident.name == sym::as_ref) && {
89+
let arg_type = cx.typeck_results().expr_ty(receiver);
90+
let base_type = arg_type.peel_refs();
91+
base_type.is_str() || is_type_lang_item(cx, base_type, hir::LangItem::String)
92+
} {
93+
receiver
94+
} else {
95+
break;
96+
}
97+
},
98+
_ => break,
99+
};
100+
}
101+
arg_root
102+
}
103+
104+
fn contains_call<'a>(cx: &LateContext<'a>, arg: &'a hir::Expr<'a>) -> bool {
105+
for_each_expr(cx, arg, |expr| {
106+
if matches!(expr.kind, hir::ExprKind::MethodCall { .. } | hir::ExprKind::Call { .. })
107+
&& !is_inside_always_const_context(cx.tcx, expr.hir_id)
108+
{
109+
ControlFlow::Break(())
110+
} else {
111+
ControlFlow::Continue(())
112+
}
113+
})
114+
.is_some()
115+
}

0 commit comments

Comments
 (0)