X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fdisallowed_methods.rs;h=53973ab792a91a50cb55da6c89e8e8d6cbdd5c69;hb=cd135749920d85596bc539ce393d02698b49429f;hp=4c12202c84ab39da96a0c1a54e5b7cb78a43f19c;hpb=bb7131c6dd458b5591e9388812812429841ed0df;p=rust.git diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs index 4c12202c84a..53973ab792a 100644 --- a/clippy_lints/src/disallowed_methods.rs +++ b/clippy_lints/src/disallowed_methods.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::fn_def_id; +use clippy_utils::{fn_def_id, get_parent_expr, path_def_id}; -use rustc_hir::{def::Res, def_id::DefIdMap, Expr}; +use rustc_hir::{def::Res, def_id::DefIdMap, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -84,7 +84,15 @@ fn check_crate(&mut self, cx: &LateContext<'_>) { } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - let def_id = match fn_def_id(cx, expr) { + let uncalled_path = if let Some(parent) = get_parent_expr(cx, expr) + && let ExprKind::Call(receiver, _) = parent.kind + && receiver.hir_id == expr.hir_id + { + None + } else { + path_def_id(cx, expr) + }; + let def_id = match uncalled_path.or_else(|| fn_def_id(cx, expr)) { Some(def_id) => def_id, None => return, };