mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Auto merge of #5387 - jpospychala:useless_self_fp, r=yaahc
`unused_self` false positive fixes #5351 Remove the for loop in `unused_self` so that lint enabled for one method doesn't trigger on another method. changelog: Fix false positive in `unused_self` around lint gates on impl items
This commit is contained in:
commit
563da5248d
2 changed files with 40 additions and 38 deletions
|
@ -1,7 +1,7 @@
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::{AssocItemKind, HirId, ImplItem, ImplItemKind, ImplItemRef, ItemKind, Path};
|
use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Path};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
@ -45,20 +45,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
||||||
let item = cx.tcx.hir().expect_item(parent);
|
let parent_item = cx.tcx.hir().expect_item(parent);
|
||||||
if let ItemKind::Impl {
|
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
|
||||||
of_trait: None,
|
let assoc_item = cx.tcx.associated_item(def_id);
|
||||||
items: impl_item_refs,
|
|
||||||
..
|
|
||||||
} = item.kind
|
|
||||||
{
|
|
||||||
for impl_item_ref in impl_item_refs {
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ImplItemRef {
|
if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind;
|
||||||
kind: AssocItemKind::Method { has_self: true },
|
if assoc_item.method_has_self_argument;
|
||||||
..
|
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
|
||||||
} = impl_item_ref;
|
|
||||||
if let ImplItemKind::Fn(_, body_id) = &impl_item.kind;
|
|
||||||
let body = cx.tcx.hir().body(*body_id);
|
let body = cx.tcx.hir().body(*body_id);
|
||||||
if !body.params.is_empty();
|
if !body.params.is_empty();
|
||||||
then {
|
then {
|
||||||
|
@ -83,8 +76,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UnusedSelfVisitor<'a, 'tcx> {
|
struct UnusedSelfVisitor<'a, 'tcx> {
|
||||||
|
|
|
@ -42,6 +42,17 @@ mod unused_self_allow {
|
||||||
impl B {
|
impl B {
|
||||||
fn unused_self_move(self) {}
|
fn unused_self_move(self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct C {}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
|
impl C {
|
||||||
|
#[warn(clippy::unused_self)]
|
||||||
|
fn some_fn((): ()) {}
|
||||||
|
|
||||||
|
// shouldn't trigger
|
||||||
|
fn unused_self_move(self) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod used_self {
|
mod used_self {
|
||||||
|
|
Loading…
Reference in a new issue