Skip to content

Commit fa1a690

Browse files
committed
iter_not_returning_iterator:
* Check HIR tree first. * Check name by symbol.
1 parent ca5c281 commit fa1a690

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

clippy_lints/src/iter_not_returning_iterator.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::{FnSig, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
7-
use rustc_span::symbol::sym;
7+
use rustc_span::{sym, Symbol};
88

99
declare_clippy_lint! {
1010
/// ### What it does
@@ -43,30 +43,27 @@ declare_lint_pass!(IterNotReturningIterator => [ITER_NOT_RETURNING_ITERATOR]);
4343

4444
impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
4545
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
46-
let name = item.ident.name.as_str();
47-
if matches!(name, "iter" | "iter_mut") {
48-
if let TraitItemKind::Fn(fn_sig, _) = &item.kind {
49-
check_sig(cx, name, fn_sig, item.owner_id.def_id);
50-
}
46+
if let TraitItemKind::Fn(fn_sig, _) = &item.kind
47+
&& matches!(item.ident.name, sym::iter | sym::iter_mut)
48+
{
49+
check_sig(cx, item.ident.name, fn_sig, item.owner_id.def_id);
5150
}
5251
}
5352

5453
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) {
55-
let name = item.ident.name.as_str();
56-
if matches!(name, "iter" | "iter_mut")
54+
if let ImplItemKind::Fn(fn_sig, _) = &item.kind
55+
&& matches!(item.ident.name, sym::iter | sym::iter_mut)
5756
&& !matches!(
5857
cx.tcx.parent_hir_node(item.hir_id()),
5958
Node::Item(Item { kind: ItemKind::Impl(i), .. }) if i.of_trait.is_some()
6059
)
6160
{
62-
if let ImplItemKind::Fn(fn_sig, _) = &item.kind {
63-
check_sig(cx, name, fn_sig, item.owner_id.def_id);
64-
}
61+
check_sig(cx, item.ident.name, fn_sig, item.owner_id.def_id);
6562
}
6663
}
6764
}
6865

69-
fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) {
66+
fn check_sig(cx: &LateContext<'_>, name: Symbol, sig: &FnSig<'_>, fn_id: LocalDefId) {
7067
if sig.decl.implicit_self.has_implicit_self() {
7168
let ret_ty = cx
7269
.tcx

0 commit comments

Comments
 (0)