Skip to content

Commit 37a2de1

Browse files
committed
Move match_function_call to utils
1 parent 5317efb commit 37a2de1

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

clippy_lints/src/assertions_on_constants.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::consts::{constant, Constant};
22
use crate::utils::paths;
3-
use crate::utils::{is_direct_expn_of, is_expn_of, match_def_path, snippet_opt, span_help_and_lint};
3+
use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_help_and_lint};
44
use if_chain::if_chain;
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -145,23 +145,3 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E
145145
}
146146
None
147147
}
148-
149-
/// Matches a function call with the given path and returns the arguments.
150-
///
151-
/// Usage:
152-
///
153-
/// ```rust,ignore
154-
/// if let Some(args) = match_function_call(cx, begin_panic_call, &paths::BEGIN_PANIC);
155-
/// ```
156-
fn match_function_call<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, path: &[&str]) -> Option<&'a [Expr]> {
157-
if_chain! {
158-
if let ExprKind::Call(ref fun, ref args) = expr.kind;
159-
if let ExprKind::Path(ref qpath) = fun.kind;
160-
if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id();
161-
if match_def_path(cx, fun_def_id, path);
162-
then {
163-
return Some(&args)
164-
}
165-
};
166-
None
167-
}

clippy_lints/src/utils/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,30 @@ pub fn has_iter_method(cx: &LateContext<'_, '_>, probably_ref_ty: Ty<'_>) -> Opt
10851085
None
10861086
}
10871087

1088+
/// Matches a function call with the given path and returns the arguments.
1089+
///
1090+
/// Usage:
1091+
///
1092+
/// ```rust,ignore
1093+
/// if let Some(args) = match_function_call(cx, begin_panic_call, &paths::BEGIN_PANIC);
1094+
/// ```
1095+
pub fn match_function_call<'a, 'tcx>(
1096+
cx: &LateContext<'a, 'tcx>,
1097+
expr: &'tcx Expr,
1098+
path: &[&str],
1099+
) -> Option<&'a [Expr]> {
1100+
if_chain! {
1101+
if let ExprKind::Call(ref fun, ref args) = expr.kind;
1102+
if let ExprKind::Path(ref qpath) = fun.kind;
1103+
if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id();
1104+
if match_def_path(cx, fun_def_id, path);
1105+
then {
1106+
return Some(&args)
1107+
}
1108+
};
1109+
None
1110+
}
1111+
10881112
#[cfg(test)]
10891113
mod test {
10901114
use super::{trim_multiline, without_block_comments};

0 commit comments

Comments
 (0)