iter_not_returning_iterator
:
* Check HIR tree first. * Check name by symbol.
This commit is contained in:
parent
ca5c2813eb
commit
fa1a690b23
1 changed files with 9 additions and 12 deletions
|
@ -4,7 +4,7 @@ use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::{FnSig, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind};
|
use rustc_hir::{FnSig, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::{sym, Symbol};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
|
@ -43,30 +43,27 @@ declare_lint_pass!(IterNotReturningIterator => [ITER_NOT_RETURNING_ITERATOR]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
|
impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
|
||||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
|
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
|
||||||
let name = item.ident.name.as_str();
|
if let TraitItemKind::Fn(fn_sig, _) = &item.kind
|
||||||
if matches!(name, "iter" | "iter_mut") {
|
&& matches!(item.ident.name, sym::iter | sym::iter_mut)
|
||||||
if let TraitItemKind::Fn(fn_sig, _) = &item.kind {
|
{
|
||||||
check_sig(cx, name, fn_sig, item.owner_id.def_id);
|
check_sig(cx, item.ident.name, fn_sig, item.owner_id.def_id);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) {
|
||||||
let name = item.ident.name.as_str();
|
if let ImplItemKind::Fn(fn_sig, _) = &item.kind
|
||||||
if matches!(name, "iter" | "iter_mut")
|
&& matches!(item.ident.name, sym::iter | sym::iter_mut)
|
||||||
&& !matches!(
|
&& !matches!(
|
||||||
cx.tcx.parent_hir_node(item.hir_id()),
|
cx.tcx.parent_hir_node(item.hir_id()),
|
||||||
Node::Item(Item { kind: ItemKind::Impl(i), .. }) if i.of_trait.is_some()
|
Node::Item(Item { kind: ItemKind::Impl(i), .. }) if i.of_trait.is_some()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if let ImplItemKind::Fn(fn_sig, _) = &item.kind {
|
check_sig(cx, item.ident.name, fn_sig, item.owner_id.def_id);
|
||||||
check_sig(cx, name, fn_sig, item.owner_id.def_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) {
|
fn check_sig(cx: &LateContext<'_>, name: Symbol, sig: &FnSig<'_>, fn_id: LocalDefId) {
|
||||||
if sig.decl.implicit_self.has_implicit_self() {
|
if sig.decl.implicit_self.has_implicit_self() {
|
||||||
let ret_ty = cx
|
let ret_ty = cx
|
||||||
.tcx
|
.tcx
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue