mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
iter_not_returning_iterator:
* Check HIR tree first. * Check name by symbol.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
use rustc_hir::{FnSig, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{sym, Symbol};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
@@ -43,30 +43,27 @@
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
|
||||
let name = item.ident.name.as_str();
|
||||
if matches!(name, "iter" | "iter_mut") {
|
||||
if let TraitItemKind::Fn(fn_sig, _) = &item.kind {
|
||||
check_sig(cx, name, fn_sig, item.owner_id.def_id);
|
||||
}
|
||||
if let TraitItemKind::Fn(fn_sig, _) = &item.kind
|
||||
&& matches!(item.ident.name, sym::iter | sym::iter_mut)
|
||||
{
|
||||
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>) {
|
||||
let name = item.ident.name.as_str();
|
||||
if matches!(name, "iter" | "iter_mut")
|
||||
if let ImplItemKind::Fn(fn_sig, _) = &item.kind
|
||||
&& matches!(item.ident.name, sym::iter | sym::iter_mut)
|
||||
&& !matches!(
|
||||
cx.tcx.parent_hir_node(item.hir_id()),
|
||||
Node::Item(Item { kind: ItemKind::Impl(i), .. }) if i.of_trait.is_some()
|
||||
)
|
||||
{
|
||||
if let ImplItemKind::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_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() {
|
||||
let ret_ty = cx
|
||||
.tcx
|
||||
|
||||
Reference in New Issue
Block a user