Remove redundant work in trait_ref_of_method.
This commit is contained in:
parent
fc811f7e2e
commit
a25c195101
10 changed files with 12 additions and 16 deletions
|
|
@ -273,7 +273,7 @@ impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {
|
|||
// Only lint on inherent methods, not trait methods.
|
||||
if let ImplItemKind::Fn(.., body_id) = item.kind
|
||||
&& !item.generics.params.is_empty()
|
||||
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none()
|
||||
&& trait_ref_of_method(cx, item.owner_id).is_none()
|
||||
&& !is_empty_body(cx, body_id)
|
||||
&& (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id))
|
||||
&& !item.span.in_external_macro(cx.sess().source_map())
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
|
|||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
|
||||
} else if is_public && !is_proc_macro(attrs) && trait_ref_of_method(cx, item.owner_id.def_id).is_none() {
|
||||
} else if is_public && !is_proc_macro(attrs) && trait_ref_of_method(cx, item.owner_id).is_none() {
|
||||
check_must_use_candidate(
|
||||
cx,
|
||||
sig.decl,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ pub(super) fn check_impl_item<'tcx>(
|
|||
// Don't lint if method is a trait's implementation, we can't do anything about those
|
||||
if let hir::ImplItemKind::Fn(ref sig, _) = item.kind
|
||||
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span)
|
||||
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none()
|
||||
&& trait_ref_of_method(cx, item.owner_id).is_none()
|
||||
{
|
||||
if cx.effective_visibilities.is_exported(item.owner_id.def_id) {
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
|||
// Check if return type is String
|
||||
&& is_type_lang_item(cx, return_ty(cx, impl_item.owner_id), LangItem::String)
|
||||
// Filters instances of to_string which are required by a trait
|
||||
&& trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none()
|
||||
&& trait_ref_of_method(cx, impl_item.owner_id).is_none()
|
||||
{
|
||||
show_lint(cx, impl_item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
|
|||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Fn(ref sig, id) = item.kind {
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.owner_id.def_id).is_none();
|
||||
let report_extra_lifetimes = trait_ref_of_method(cx, item.owner_id).is_none();
|
||||
check_fn_inner(
|
||||
cx,
|
||||
sig,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_abi::ExternAbi;
|
|||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{self as hir, Body, Constness, FnDecl, GenericParamKind};
|
||||
use rustc_hir::{self as hir, Body, Constness, FnDecl, GenericParamKind, OwnerId};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::impl_lint_pass;
|
||||
|
|
@ -125,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
|
|||
}
|
||||
},
|
||||
FnKind::Method(_, sig, ..) => {
|
||||
if already_const(sig.header) || trait_ref_of_method(cx, def_id).is_some() {
|
||||
if already_const(sig.header) || trait_ref_of_method(cx, OwnerId { def_id }).is_some() {
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType<'tcx> {
|
|||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
|
||||
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind
|
||||
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none()
|
||||
&& trait_ref_of_method(cx, item.owner_id).is_none()
|
||||
{
|
||||
self.check_sig(cx, item.owner_id.def_id, sig.decl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(
|
|||
let rty = cx.typeck_results().expr_ty(rhs);
|
||||
if let Some((_, lang_item)) = binop_traits(op.node)
|
||||
&& let Some(trait_id) = cx.tcx.lang_items().get(lang_item)
|
||||
&& let parent_fn = cx.tcx.hir_get_parent_item(e.hir_id).def_id
|
||||
&& let parent_fn = cx.tcx.hir_get_parent_item(e.hir_id)
|
||||
&& trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id)
|
||||
&& implements_trait(cx, ty, trait_id, &[rty.into()])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ fn check_expr_inner<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, bin
|
|||
&& let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn)
|
||||
&& let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind
|
||||
&& let body = cx.tcx.hir_body(body_id)
|
||||
&& let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id
|
||||
&& let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id)
|
||||
&& let Some(trait_ref) = trait_ref_of_method(cx, parent_fn)
|
||||
&& let trait_id = trait_ref.path.res.def_id()
|
||||
&& ![binop_trait_id, op_assign_trait_id].contains(&trait_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue