Skip to content

Commit 8e28b2f

Browse files
committed
move is_trait_impl_item check from functions.rs to utils
1 parent a7b3b9f commit 8e28b2f

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

clippy_lints/src/functions.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::utils::{
2-
attr_by_name, attrs::is_proc_macro, is_must_use_ty, iter_input_pats, match_def_path, must_use_attr, qpath_res,
3-
return_ty, snippet, snippet_opt, span_lint, span_lint_and_help, span_lint_and_then, trait_ref_of_method,
4-
type_is_unsafe_function,
2+
attr_by_name, attrs::is_proc_macro, is_must_use_ty, is_trait_impl_item, iter_input_pats, match_def_path,
3+
must_use_attr, qpath_res, return_ty, snippet, snippet_opt, span_lint, span_lint_and_help, span_lint_and_then,
4+
trait_ref_of_method, type_is_unsafe_function,
55
};
6-
use matches::matches;
76
use rustc::hir::map::Map;
87
use rustc::lint::in_external_macro;
98
use rustc::ty::{self, Ty};
@@ -195,20 +194,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
195194
span: Span,
196195
hir_id: hir::HirId,
197196
) {
198-
let is_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
199-
matches!(item.kind, hir::ItemKind::Impl{ of_trait: Some(_), .. })
200-
} else {
201-
false
202-
};
203-
204197
let unsafety = match kind {
205198
intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _, _) => unsafety,
206199
intravisit::FnKind::Method(_, sig, _, _) => sig.header.unsafety,
207200
intravisit::FnKind::Closure(_) => return,
208201
};
209202

210203
// don't warn for implementations, it's not their fault
211-
if !is_impl {
204+
if !is_trait_impl_item(cx, hir_id) {
212205
// don't lint extern functions decls, it's not their fault either
213206
match kind {
214207
intravisit::FnKind::Method(

clippy_lints/src/utils/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,3 +1354,11 @@ pub fn is_no_std_crate(krate: &Crate<'_>) -> bool {
13541354
}
13551355
})
13561356
}
1357+
1358+
pub fn is_trait_impl_item(cx: &LateContext<'_, '_>, hir_id: HirId) -> bool {
1359+
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
1360+
matches!(item.kind, ItemKind::Impl{ of_trait: Some(_), .. })
1361+
} else {
1362+
false
1363+
}
1364+
}

0 commit comments

Comments
 (0)