Remove path_to_local_id
This commit is contained in:
parent
53675ce061
commit
a6078f87db
42 changed files with 150 additions and 145 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::get_enclosing_block;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::visitors::{Visitable, for_each_expr};
|
||||
use clippy_utils::{get_enclosing_block, path_to_local_id};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_hir::{Body, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -81,7 +81,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
|
|||
// Inspect all expressions and sub-expressions in the block.
|
||||
for_each_expr(cx, block, |expr| {
|
||||
// Ignore expressions that are not simply `id`.
|
||||
if !path_to_local_id(expr, id) {
|
||||
if expr.res_local_id() != Some(id) {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
|
|||
// id = ...; // Not reading `id`.
|
||||
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
|
||||
&& let ExprKind::Assign(lhs, ..) = parent.kind
|
||||
&& path_to_local_id(lhs, id)
|
||||
&& lhs.res_local_id() == Some(id)
|
||||
{
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
|
|||
// have side effects, so consider them a read.
|
||||
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
|
||||
&& let ExprKind::MethodCall(_, receiver, args, _) = parent.kind
|
||||
&& path_to_local_id(receiver, id)
|
||||
&& receiver.res_local_id() == Some(id)
|
||||
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
|
||||
&& !method_def_id.is_local()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use clippy_utils::higher::VecArgs;
|
|||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
|
||||
use clippy_utils::usage::{local_used_after_expr, local_used_in};
|
||||
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local_id};
|
||||
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate};
|
||||
use rustc_abi::ExternAbi;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
|
|
@ -305,7 +305,7 @@ fn check_inputs(
|
|||
matches!(
|
||||
p.pat.kind,
|
||||
PatKind::Binding(BindingMode::NONE, id, _, None)
|
||||
if path_to_local_id(arg, id)
|
||||
if arg.res_local_id() == Some(id)
|
||||
)
|
||||
// Only allow adjustments which change regions (i.e. re-borrowing).
|
||||
&& typeck
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||
use clippy_utils::path_to_local_id;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::visitors::is_local_used;
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -145,7 +145,7 @@ fn check_assign<'tcx>(
|
|||
&& let Some(expr) = block.stmts.iter().last()
|
||||
&& let hir::StmtKind::Semi(expr) = expr.kind
|
||||
&& let hir::ExprKind::Assign(var, value, _) = expr.kind
|
||||
&& path_to_local_id(var, decl)
|
||||
&& var.res_local_id() == Some(decl)
|
||||
{
|
||||
if block
|
||||
.stmts
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use clippy_config::Conf;
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::{is_diag_item_method, is_trait_method, path_to_local_id, sym};
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::{is_diag_item_method, is_trait_method, sym};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Body, Closure, Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -120,7 +120,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_name: Symbol) ->
|
|||
params: [param], value, ..
|
||||
} = cx.tcx.hir_body(*body)
|
||||
&& let ExprKind::MethodCall(method, receiver, [], _) = value.kind
|
||||
&& path_to_local_id(receiver, param.pat.hir_id)
|
||||
&& receiver.res_local_id() == Some(param.pat.hir_id)
|
||||
&& let Some(method_did) = cx.typeck_results().type_dependent_def_id(value.hir_id)
|
||||
{
|
||||
is_diag_item_method(cx, method_did, sym::Result) && method.ident.name == sym::ok
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::visitors::for_each_expr;
|
||||
use clippy_utils::{eq_expr_value, higher, path_to_local_id, sym};
|
||||
use clippy_utils::{eq_expr_value, higher, sym};
|
||||
use rustc_errors::{Applicability, MultiSpan};
|
||||
use rustc_hir::{Expr, ExprKind, LangItem, Node, Pat, PatKind};
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, iterable: &Expr
|
|||
{
|
||||
// Destructured iterator element `(idx, _)`, look for uses of the binding
|
||||
for_each_expr(cx, body, |expr| {
|
||||
if path_to_local_id(expr, binding_id) {
|
||||
if expr.res_local_id() == Some(binding_id) {
|
||||
check_index_usage(cx, expr, pat, enumerate_span, chars_span, chars_recv);
|
||||
}
|
||||
CONTINUE
|
||||
|
|
@ -58,7 +58,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, iterable: &Expr
|
|||
// Bound as a tuple, look for `tup.0`
|
||||
for_each_expr(cx, body, |expr| {
|
||||
if let ExprKind::Field(e, field) = expr.kind
|
||||
&& path_to_local_id(e, binding_id)
|
||||
&& e.res_local_id() == Some(binding_id)
|
||||
&& field.name == sym::integer(0)
|
||||
{
|
||||
check_index_usage(cx, expr, pat, enumerate_span, chars_span, chars_recv);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ use super::MANUAL_FLATTEN;
|
|||
use super::utils::make_iterator_snippet;
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::{HasSession, indent_of, reindent_multiline, snippet_with_applicability};
|
||||
use clippy_utils::visitors::is_local_used;
|
||||
use clippy_utils::{higher, is_refutable, path_to_local_id, peel_blocks_with_stmt, span_contains_comment};
|
||||
use clippy_utils::{higher, is_refutable, peel_blocks_with_stmt, span_contains_comment};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{Expr, Pat, PatKind};
|
||||
|
|
@ -27,7 +28,7 @@ pub(super) fn check<'tcx>(
|
|||
= higher::IfLet::hir(cx, inner_expr)
|
||||
// Ensure match_expr in `if let` statement is the same as the pat from the for-loop
|
||||
&& let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind
|
||||
&& path_to_local_id(let_expr, pat_hir_id)
|
||||
&& let_expr.res_local_id() == Some(pat_hir_id)
|
||||
// Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result`
|
||||
&& let PatKind::TupleStruct(ref qpath, [inner_pat], _) = let_pat.kind
|
||||
&& let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(qpath, let_pat.hir_id)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::ty::{has_iter_method, implements_trait};
|
||||
use clippy_utils::{get_parent_expr, is_integer_const, path_to_local_id, sugg};
|
||||
use clippy_utils::{get_parent_expr, is_integer_const, sugg};
|
||||
use rustc_ast::ast::{LitIntType, LitKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::{Visitor, walk_expr, walk_local};
|
||||
|
|
@ -176,7 +176,7 @@ impl<'tcx> Visitor<'tcx> for InitializeVisitor<'_, 'tcx> {
|
|||
}
|
||||
|
||||
// If node is the desired variable, see how it's used
|
||||
if path_to_local_id(expr, self.var_id) {
|
||||
if expr.res_local_id() == Some(self.var_id) {
|
||||
if self.past_loop {
|
||||
self.state = InitializeVisitorState::DontWarn;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ use clippy_utils::sugg::Sugg;
|
|||
use clippy_utils::ty::implements_trait;
|
||||
use clippy_utils::visitors::is_const_evaluatable;
|
||||
use clippy_utils::{
|
||||
eq_expr_value, is_diag_trait_item, is_in_const_context, is_trait_method, path_to_local_id, peel_blocks,
|
||||
peel_blocks_with_stmt, sym,
|
||||
eq_expr_value, is_diag_trait_item, is_in_const_context, is_trait_method, peel_blocks, peel_blocks_with_stmt, sym,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
|
|
@ -436,7 +435,7 @@ fn is_match_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opt
|
|||
let first = BinaryOp::new(first)?;
|
||||
let second = BinaryOp::new(second)?;
|
||||
if let PatKind::Binding(_, binding, _, None) = &last_arm.pat.kind
|
||||
&& path_to_local_id(peel_blocks_with_stmt(last_arm.body), *binding)
|
||||
&& peel_blocks_with_stmt(last_arm.body).res_local_id() == Some(*binding)
|
||||
&& last_arm.guard.is_none()
|
||||
{
|
||||
// Proceed as normal
|
||||
|
|
@ -656,8 +655,8 @@ fn is_clamp_meta_pattern<'tcx>(
|
|||
let (min, max) = (second_expr, first_expr);
|
||||
let refers_to_input = match input_hir_ids {
|
||||
Some((first_hir_id, second_hir_id)) => {
|
||||
path_to_local_id(peel_blocks(first_bin.left), first_hir_id)
|
||||
&& path_to_local_id(peel_blocks(second_bin.left), second_hir_id)
|
||||
peel_blocks(first_bin.left).res_local_id() == Some(first_hir_id)
|
||||
&& peel_blocks(second_bin.left).res_local_id() == Some(second_hir_id)
|
||||
},
|
||||
None => eq_expr_value(cx, first_bin.left, second_bin.left),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use clippy_config::Conf;
|
||||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::SpanRangeExt;
|
||||
use clippy_utils::visitors::{is_local_used, local_used_once};
|
||||
use clippy_utils::{is_trait_method, path_to_local_id, sym};
|
||||
use clippy_utils::{is_trait_method, sym};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BindingMode, ExprKind, LetStmt, Node, PatKind, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -82,7 +83,7 @@ impl LateLintPass<'_> for ManualHashOne {
|
|||
&& let ExprKind::MethodCall(seg, hashed_value, [ref_to_hasher], _) = hash_expr.kind
|
||||
&& seg.ident.name == sym::hash
|
||||
&& is_trait_method(cx, hash_expr, sym::Hash)
|
||||
&& path_to_local_id(ref_to_hasher.peel_borrows(), hasher)
|
||||
&& ref_to_hasher.peel_borrows().res_local_id() == Some(hasher)
|
||||
|
||||
&& let maybe_finish_stmt = stmts.next()
|
||||
// There should be no more statements referencing `hasher`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
|
||||
use clippy_utils::{peel_blocks, strip_pat_refs};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{ExprKind, LetStmt, MatchSource, PatKind, QPath};
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -17,7 +18,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool {
|
|||
&& args.len() == 1
|
||||
&& let PatKind::Binding(binding, arg, ..) = strip_pat_refs(&args[0]).kind
|
||||
&& let body = peel_blocks(arms[0].body)
|
||||
&& path_to_local_id(body, arg)
|
||||
&& body.res_local_id() == Some(arg)
|
||||
{
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_sugg(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::path_to_local_id;
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath};
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath};
|
||||
use clippy_utils::visitors::contains_unsafe_block;
|
||||
|
||||
use rustc_hir::LangItem::{OptionNone, OptionSome};
|
||||
|
|
@ -67,7 +66,7 @@ fn is_some_expr(cx: &LateContext<'_>, target: HirId, ctxt: SyntaxContext, expr:
|
|||
{
|
||||
return ctxt == expr.span.ctxt()
|
||||
&& callee.res(cx).ctor_parent(cx).is_lang_item(cx, OptionSome)
|
||||
&& path_to_local_id(arg, target);
|
||||
&& arg.res_local_id() == Some(target);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use crate::map_unit_fn::OPTION_MAP_UNIT_FN;
|
||||
use crate::matches::MATCH_AS_REF;
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath};
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath};
|
||||
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
|
||||
use clippy_utils::sugg::Sugg;
|
||||
use clippy_utils::ty::{is_copy, is_unsafe_fn, peel_and_count_ty_refs};
|
||||
use clippy_utils::{
|
||||
CaptureKind, can_move_expr_to_closure, expr_requires_coercion, is_else_clause, is_lint_allowed, path_to_local_id,
|
||||
peel_blocks, peel_hir_expr_refs, peel_hir_expr_while,
|
||||
CaptureKind, can_move_expr_to_closure, expr_requires_coercion, is_else_clause, is_lint_allowed, peel_blocks,
|
||||
peel_hir_expr_refs, peel_hir_expr_while,
|
||||
};
|
||||
use rustc_ast::util::parser::ExprPrecedence;
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -138,7 +138,7 @@ where
|
|||
{
|
||||
snippet_with_applicability(cx, func.span, "..", &mut app).into_owned()
|
||||
} else {
|
||||
if path_to_local_id(some_expr.expr, id)
|
||||
if some_expr.expr.res_local_id() == Some(id)
|
||||
&& !is_lint_allowed(cx, MATCH_AS_REF, expr.hir_id)
|
||||
&& binding_ref.is_some()
|
||||
{
|
||||
|
|
@ -190,7 +190,7 @@ pub struct SuggInfo<'a> {
|
|||
fn can_pass_as_func<'tcx>(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||
match expr.kind {
|
||||
ExprKind::Call(func, [arg])
|
||||
if path_to_local_id(arg, binding)
|
||||
if arg.res_local_id() == Some(binding)
|
||||
&& cx.typeck_results().expr_adjustments(arg).is_empty()
|
||||
&& !is_unsafe_fn(cx, cx.typeck_results().expr_ty(func).peel_refs()) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::visitors::is_local_used;
|
||||
use clippy_utils::{path_to_local_id, peel_blocks, peel_ref_operators, strip_pat_refs};
|
||||
use clippy_utils::{peel_blocks, peel_ref_operators, strip_pat_refs};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BinOpKind, Closure, Expr, ExprKind, PatKind};
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
|
|||
.is_diag_item(cx, sym::SliceIter)
|
||||
&& let operand_is_arg = (|expr| {
|
||||
let expr = peel_ref_operators(cx, peel_blocks(expr));
|
||||
path_to_local_id(expr, arg_id)
|
||||
expr.res_local_id() == Some(arg_id)
|
||||
})
|
||||
&& let needle = if operand_is_arg(l) {
|
||||
r
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
|
||||
use clippy_utils::macros::{is_panic, matching_root_macro_call, root_macro_call};
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::{indent_of, reindent_multiline, snippet};
|
||||
use clippy_utils::{SpanlessEq, higher, is_trait_method, path_to_local_id, peel_blocks, sym};
|
||||
use clippy_utils::{SpanlessEq, higher, is_trait_method, peel_blocks, sym};
|
||||
use hir::{Body, HirId, MatchSource, Pat};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
|
|
@ -134,16 +134,16 @@ impl<'tcx> OffendingFilterExpr<'tcx> {
|
|||
_ => map_arg,
|
||||
}
|
||||
// .map(|y| y[.acceptable_method()].unwrap())
|
||||
&& let simple_equal = (path_to_local_id(receiver, filter_param_id)
|
||||
&& path_to_local_id(map_arg_peeled, map_param_id))
|
||||
&& let simple_equal = (receiver.res_local_id() == Some(filter_param_id)
|
||||
&& map_arg_peeled.res_local_id() == Some(map_param_id))
|
||||
&& let eq_fallback = (|a: &Expr<'_>, b: &Expr<'_>| {
|
||||
// in `filter(|x| ..)`, replace `*x` with `x`
|
||||
let a_path = if !is_filter_param_ref
|
||||
&& let ExprKind::Unary(UnOp::Deref, expr_path) = a.kind
|
||||
{ expr_path } else { a };
|
||||
// let the filter closure arg and the map closure arg be equal
|
||||
path_to_local_id(a_path, filter_param_id)
|
||||
&& path_to_local_id(b, map_param_id)
|
||||
a_path.res_local_id() == Some(filter_param_id)
|
||||
&& b.res_local_id() == Some(map_param_id)
|
||||
&& cx.typeck_results().expr_ty_adjusted(a) == cx.typeck_results().expr_ty_adjusted(b)
|
||||
})
|
||||
&& (simple_equal
|
||||
|
|
@ -166,7 +166,7 @@ impl<'tcx> OffendingFilterExpr<'tcx> {
|
|||
let expr_uses_local = |pat: &Pat<'_>, expr: &Expr<'_>| {
|
||||
if let PatKind::TupleStruct(QPath::Resolved(_, path), [subpat], _) = pat.kind
|
||||
&& let PatKind::Binding(_, local_id, ident, _) = subpat.kind
|
||||
&& path_to_local_id(expr.peel_blocks(), local_id)
|
||||
&& expr.peel_blocks().res_local_id() == Some(local_id)
|
||||
&& let Some(local_variant_def_id) = path.res.opt_def_id()
|
||||
&& local_variant_def_id == variant_def_id
|
||||
{
|
||||
|
|
@ -204,7 +204,7 @@ impl<'tcx> OffendingFilterExpr<'tcx> {
|
|||
_ => return None,
|
||||
};
|
||||
|
||||
if path_to_local_id(scrutinee, map_param_id)
|
||||
if scrutinee.res_local_id() == Some(map_param_id)
|
||||
// else branch should be a `panic!` or `unreachable!` macro call
|
||||
&& let Some(mac) = root_macro_call(else_.peel_blocks().span)
|
||||
&& (is_panic(cx, mac.def_id) || cx.tcx.opt_item_name(mac.def_id) == Some(sym::unreachable))
|
||||
|
|
@ -247,7 +247,7 @@ impl<'tcx> OffendingFilterExpr<'tcx> {
|
|||
} else if matching_root_macro_call(cx, expr.span, sym::matches_macro).is_some()
|
||||
// we know for a fact that the wildcard pattern is the second arm
|
||||
&& let ExprKind::Match(scrutinee, [arm, _], _) = expr.kind
|
||||
&& path_to_local_id(scrutinee, filter_param_id)
|
||||
&& scrutinee.res_local_id() == Some(filter_param_id)
|
||||
&& let PatKind::TupleStruct(QPath::Resolved(_, path), ..) = arm.pat.kind
|
||||
&& let Some(variant_def_id) = path.res.opt_def_id()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::{IntoSpan, SpanRangeExt};
|
||||
use clippy_utils::ty::get_field_by_name;
|
||||
use clippy_utils::visitors::{for_each_expr, for_each_expr_without_closures};
|
||||
use clippy_utils::{ExprUseNode, expr_use_ctxt, is_diag_item_method, is_diag_trait_item, path_to_local_id, sym};
|
||||
use clippy_utils::{ExprUseNode, expr_use_ctxt, is_diag_item_method, is_diag_trait_item, sym};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BindingMode, BorrowKind, ByRef, ClosureKind, Expr, ExprKind, Mutability, Node, PatKind};
|
||||
|
|
@ -29,7 +30,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
|
|||
&& let ExprKind::Block(block, _) = body.value.kind
|
||||
&& let Some(final_expr) = block.expr
|
||||
&& !block.stmts.is_empty()
|
||||
&& path_to_local_id(final_expr, arg_id)
|
||||
&& final_expr.res_local_id() == Some(arg_id)
|
||||
&& typeck.expr_adjustments(final_expr).is_empty()
|
||||
{
|
||||
let mut requires_copy = false;
|
||||
|
|
@ -46,7 +47,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
|
|||
if let ExprKind::Closure(c) = e.kind {
|
||||
// Nested closures don't need to treat returns specially.
|
||||
let _: Option<!> = for_each_expr(cx, cx.tcx.hir_body(c.body).value, |e| {
|
||||
if path_to_local_id(e, arg_id) {
|
||||
if e.res_local_id() == Some(arg_id) {
|
||||
let (kind, same_ctxt) = check_use(cx, e);
|
||||
match (kind, same_ctxt && e.span.ctxt() == ctxt) {
|
||||
(_, false) | (UseKind::Deref | UseKind::Return(..), true) => {
|
||||
|
|
@ -64,7 +65,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
|
|||
});
|
||||
} else if matches!(e.kind, ExprKind::Ret(_)) {
|
||||
ret_count += 1;
|
||||
} else if path_to_local_id(e, arg_id) {
|
||||
} else if e.res_local_id() == Some(arg_id) {
|
||||
let (kind, same_ctxt) = check_use(cx, e);
|
||||
match (kind, same_ctxt && e.span.ctxt() == ctxt) {
|
||||
(UseKind::Return(..), false) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::path_to_local_id;
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath};
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath};
|
||||
use clippy_utils::source::{SpanRangeExt, indent_of, reindent_multiline};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::LangItem::{ResultErr, ResultOk};
|
||||
|
|
@ -60,7 +59,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
|
|||
&& let ExprKind::Call(callee, [ok_arg]) = body.value.kind
|
||||
&& callee.res(cx).ctor_parent(cx).is_lang_item(cx, ResultOk)
|
||||
{
|
||||
path_to_local_id(ok_arg, param_id)
|
||||
ok_arg.res_local_id() == Some(param_id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use clippy_utils::res::{MaybeDef, MaybeQPath};
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Closure, Expr, ExprKind, HirId, StmtKind, UnOp};
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -9,7 +9,7 @@ use super::NEEDLESS_CHARACTER_ITERATION;
|
|||
use super::utils::get_last_chain_binding_hir_id;
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::source::SpanRangeExt;
|
||||
use clippy_utils::{path_to_local_id, peel_blocks, sym};
|
||||
use clippy_utils::{peel_blocks, sym};
|
||||
|
||||
fn peels_expr_ref<'a, 'tcx>(mut expr: &'a Expr<'tcx>) -> &'a Expr<'tcx> {
|
||||
while let ExprKind::AddrOf(_, _, e) = expr.kind {
|
||||
|
|
@ -33,7 +33,7 @@ fn handle_expr(
|
|||
// `is_ascii`, then only `.all()` should warn.
|
||||
if revert != is_all
|
||||
&& method.ident.name == sym::is_ascii
|
||||
&& path_to_local_id(receiver, first_param)
|
||||
&& receiver.res_local_id() == Some(first_param)
|
||||
&& let char_arg_ty = cx.typeck_results().expr_ty_adjusted(receiver).peel_refs()
|
||||
&& *char_arg_ty.kind() == ty::Char
|
||||
&& let Some(snippet) = before_chars.get_source_text(cx)
|
||||
|
|
@ -77,7 +77,7 @@ fn handle_expr(
|
|||
// `is_ascii`, then only `.all()` should warn.
|
||||
if revert != is_all
|
||||
&& fn_path.ty_rel_def(cx).is_diag_item(cx, sym::char_is_ascii)
|
||||
&& path_to_local_id(peels_expr_ref(arg), first_param)
|
||||
&& peels_expr_ref(arg).res_local_id() == Some(first_param)
|
||||
&& let Some(snippet) = before_chars.get_source_text(cx)
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ use clippy_utils::source::{snippet, snippet_with_applicability};
|
|||
use clippy_utils::sugg::Sugg;
|
||||
use clippy_utils::ty::{has_non_owning_mutable_access, make_normalized_projection, make_projection};
|
||||
use clippy_utils::{
|
||||
CaptureKind, can_move_expr_to_closure, fn_def_id, get_enclosing_block, higher, is_trait_method, path_to_local_id,
|
||||
sym,
|
||||
CaptureKind, can_move_expr_to_closure, fn_def_id, get_enclosing_block, higher, is_trait_method, sym,
|
||||
};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{Applicability, MultiSpan};
|
||||
|
|
@ -345,7 +344,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
if path_to_local_id(recv, self.target) {
|
||||
if recv.res_local_id() == Some(self.target) {
|
||||
if self
|
||||
.illegal_mutable_capture_ids
|
||||
.intersection(&self.current_mutably_captured_ids)
|
||||
|
|
@ -401,7 +400,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
// Check if the collection is used for anything else
|
||||
if path_to_local_id(expr, self.target) {
|
||||
if expr.res_local_id() == Some(self.target) {
|
||||
self.seen_other = true;
|
||||
} else {
|
||||
walk_expr(self, expr);
|
||||
|
|
@ -463,7 +462,7 @@ impl<'tcx> Visitor<'tcx> for UsedCountVisitor<'_, 'tcx> {
|
|||
type NestedFilter = nested_filter::OnlyBodies;
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if path_to_local_id(expr, self.id) {
|
||||
if expr.res_local_id() == Some(self.id) {
|
||||
self.count += 1;
|
||||
} else {
|
||||
walk_expr(self, expr);
|
||||
|
|
@ -548,7 +547,7 @@ impl<'tcx> Visitor<'tcx> for IteratorMethodCheckVisitor<'_, 'tcx> {
|
|||
&& (recv.hir_id == self.hir_id_of_expr
|
||||
|| self
|
||||
.hir_id_of_let_binding
|
||||
.is_some_and(|hid| path_to_local_id(recv, hid)))
|
||||
.is_some_and(|hid| recv.res_local_id() == Some(hid)))
|
||||
&& !is_trait_method(self.cx, expr, sym::Iterator)
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::peel_blocks;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::{path_to_local_id, peel_blocks};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -51,7 +51,7 @@ pub(super) fn check(
|
|||
|
||||
match &closure_expr.kind {
|
||||
hir::ExprKind::MethodCall(_, receiver, [], _) => {
|
||||
if path_to_local_id(receiver, closure_body.params[0].pat.hir_id)
|
||||
if receiver.res_local_id() == Some(closure_body.params[0].pat.hir_id)
|
||||
&& let adj = cx
|
||||
.typeck_results()
|
||||
.expr_adjustments(receiver)
|
||||
|
|
@ -72,7 +72,7 @@ pub(super) fn check(
|
|||
if let hir::ExprKind::Unary(hir::UnOp::Deref, inner1) = inner.kind
|
||||
&& let hir::ExprKind::Unary(hir::UnOp::Deref, inner2) = inner1.kind
|
||||
{
|
||||
path_to_local_id(inner2, closure_body.params[0].pat.hir_id)
|
||||
inner2.res_local_id() == Some(closure_body.params[0].pat.hir_id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use clippy_utils::consts::{ConstEvalCtxt, Constant};
|
||||
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet_with_context;
|
||||
use clippy_utils::usage::local_used_after_expr;
|
||||
use clippy_utils::visitors::{Descend, for_each_expr};
|
||||
use clippy_utils::{is_diag_item_method, path_to_local_id, paths, sym};
|
||||
use clippy_utils::{is_diag_item_method, paths, sym};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{
|
||||
|
|
@ -214,7 +215,7 @@ fn indirect_usage<'tcx>(
|
|||
{
|
||||
let mut path_to_binding = None;
|
||||
let _: Option<!> = for_each_expr(cx, init_expr, |e| {
|
||||
if path_to_local_id(e, binding) {
|
||||
if e.res_local_id() == Some(binding) {
|
||||
path_to_binding = Some(e);
|
||||
}
|
||||
ControlFlow::Continue(Descend::from(path_to_binding.is_none()))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use super::utils::clone_or_copy_needed;
|
||||
use clippy_utils::diagnostics::span_lint;
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath};
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath};
|
||||
use clippy_utils::ty::is_copy;
|
||||
use clippy_utils::usage::mutated_variables;
|
||||
use clippy_utils::visitors::{Descend, for_each_expr_without_closures};
|
||||
use clippy_utils::{is_trait_method, path_to_local_id, sym};
|
||||
use clippy_utils::{is_trait_method, sym};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::LangItem::{OptionNone, OptionSome};
|
||||
|
|
@ -97,7 +97,7 @@ fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tc
|
|||
match expr.kind {
|
||||
hir::ExprKind::Call(func, args) => {
|
||||
if func.res(cx).ctor_parent(cx).is_lang_item(cx, OptionSome) {
|
||||
if path_to_local_id(&args[0], arg_id) {
|
||||
if args[0].res_local_id() == Some(arg_id) {
|
||||
return (false, false);
|
||||
}
|
||||
return (true, false);
|
||||
|
|
@ -107,7 +107,7 @@ fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tc
|
|||
hir::ExprKind::MethodCall(segment, recv, [arg], _) => {
|
||||
if segment.ident.name == sym::then_some
|
||||
&& cx.typeck_results().expr_ty(recv).is_bool()
|
||||
&& path_to_local_id(arg, arg_id)
|
||||
&& arg.res_local_id() == Some(arg_id)
|
||||
{
|
||||
(false, true)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::{is_trait_method, path_to_local_id, peel_blocks, strip_pat_refs};
|
||||
use clippy_utils::{is_trait_method, peel_blocks, strip_pat_refs};
|
||||
use rustc_ast::ast;
|
||||
use rustc_data_structures::packed::Pu128;
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -74,8 +75,8 @@ fn check_fold_with_op(
|
|||
&& let PatKind::Binding(_, first_arg_id, ..) = strip_pat_refs(param_a.pat).kind
|
||||
&& let PatKind::Binding(_, second_arg_id, second_arg_ident, _) = strip_pat_refs(param_b.pat).kind
|
||||
|
||||
&& path_to_local_id(left_expr, first_arg_id)
|
||||
&& (replacement.has_args || path_to_local_id(right_expr, second_arg_id))
|
||||
&& left_expr.res_local_id() == Some(first_arg_id)
|
||||
&& (replacement.has_args || right_expr.res_local_id() == Some(second_arg_id))
|
||||
{
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ use std::borrow::Cow;
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::eager_or_lazy::switch_to_eager_eval;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::sugg::{Sugg, make_binop};
|
||||
use clippy_utils::ty::{implements_trait, is_copy};
|
||||
use clippy_utils::visitors::is_local_used;
|
||||
use clippy_utils::{get_parent_expr, is_from_proc_macro, path_to_local_id};
|
||||
use clippy_utils::{get_parent_expr, is_from_proc_macro};
|
||||
use rustc_ast::LitKind::Bool;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BinOpKind, Expr, ExprKind, PatKind};
|
||||
|
|
@ -76,11 +76,11 @@ pub(super) fn check<'a>(
|
|||
// .map_or(true, |x| x != y)
|
||||
// .map_or(true, |x| y != x) - swapped comparison
|
||||
&& ((BinOpKind::Eq == op.node && !def_bool) || (BinOpKind::Ne == op.node && def_bool))
|
||||
&& let non_binding_location = if path_to_local_id(l, hir_id) { r } else { l }
|
||||
&& let non_binding_location = if l.res_local_id() == Some(hir_id) { r } else { l }
|
||||
&& switch_to_eager_eval(cx, non_binding_location)
|
||||
// xor, because if its both then that's a strange edge case and
|
||||
// if its both then that's a strange edge case and
|
||||
// we can just ignore it, since by default clippy will error on this
|
||||
&& (path_to_local_id(l, hir_id) ^ path_to_local_id(r, hir_id))
|
||||
&& (l.res_local_id() == Some(hir_id)) != (r.res_local_id() == Some(hir_id))
|
||||
&& !is_local_used(cx, non_binding_location, hir_id)
|
||||
&& let typeck_results = cx.typeck_results()
|
||||
&& let l_ty = typeck_results.expr_ty(l)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs, should_call_clone_as_function};
|
||||
use clippy_utils::{get_parent_expr, is_diag_trait_item, path_to_local_id, peel_blocks, strip_pat_refs};
|
||||
use clippy_utils::{get_parent_expr, is_diag_trait_item, peel_blocks, strip_pat_refs};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{self as hir, LangItem};
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -137,7 +138,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
|
|||
// no autoderefs
|
||||
&& !cx.typeck_results().expr_adjustments(obj).iter()
|
||||
.any(|a| matches!(a.kind, Adjust::Deref(Some(..))))
|
||||
&& path_to_local_id(obj, local_id)
|
||||
&& obj.res_local_id() == Some(local_id)
|
||||
{
|
||||
true
|
||||
} else {
|
||||
|
|
@ -146,7 +147,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
|
|||
},
|
||||
hir::ExprKind::Call(call, [recv]) => {
|
||||
if let hir::ExprKind::Path(qpath) = call.kind
|
||||
&& path_to_local_id(recv, local_id)
|
||||
&& recv.res_local_id() == Some(local_id)
|
||||
{
|
||||
check_qpath(cx, qpath, call.hir_id)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::{get_parent_expr, path_to_local_id, usage};
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::{get_parent_expr, usage};
|
||||
use rustc_hir::intravisit::{Visitor, walk_expr};
|
||||
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, QPath, Stmt, StmtKind};
|
||||
use rustc_lint::LateContext;
|
||||
|
|
@ -130,7 +130,7 @@ impl<'tcx> CloneOrCopyVisitor<'_, 'tcx> {
|
|||
fn is_binding(&self, expr: &Expr<'tcx>) -> bool {
|
||||
self.binding_hir_ids
|
||||
.iter()
|
||||
.any(|hir_id| path_to_local_id(expr, *hir_id))
|
||||
.any(|&hir_id| expr.res_local_id() == Some(hir_id))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
|
||||
use clippy_utils::macros::root_macro_call_first_node;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::{get_parent_expr, path_to_local_id, sym};
|
||||
use clippy_utils::{get_parent_expr, sym};
|
||||
use rustc_hir::intravisit::{Visitor, walk_expr};
|
||||
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -326,7 +326,7 @@ impl<'tcx> Visitor<'tcx> for ReadVisitor<'_, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
if path_to_local_id(expr, self.var)
|
||||
if expr.res_local_id() == Some(self.var)
|
||||
// Check that this is a read, not a write.
|
||||
&& !is_in_assignment_position(self.cx, expr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::{SpanRangeExt, snippet};
|
||||
use clippy_utils::ty::{implements_trait, implements_trait_with_env_from_iter, is_copy};
|
||||
use clippy_utils::visitors::{Descend, for_each_expr_without_closures};
|
||||
use clippy_utils::{is_self, path_to_local_id, peel_hir_ty_options, strip_pat_refs, sym};
|
||||
use clippy_utils::{is_self, peel_hir_ty_options, strip_pat_refs, sym};
|
||||
use rustc_abi::ExternAbi;
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
|
|
@ -361,7 +361,7 @@ fn extract_clone_suggestions<'tcx>(
|
|||
let mut spans = Vec::new();
|
||||
for_each_expr_without_closures(body, |e| {
|
||||
if let ExprKind::MethodCall(seg, recv, [], _) = e.kind
|
||||
&& path_to_local_id(recv, id)
|
||||
&& recv.res_local_id() == Some(id)
|
||||
{
|
||||
if seg.ident.name == sym::capacity {
|
||||
return ControlFlow::Break(());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::get_expr_use_or_unification_node;
|
||||
use clippy_utils::res::{MaybeQPath, MaybeResPath};
|
||||
use clippy_utils::{get_expr_use_or_unification_node, path_to_local_id};
|
||||
use core::cell::Cell;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -396,7 +396,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
|||
},
|
||||
// Parameter update e.g. `x = x + 1`
|
||||
ExprKind::Assign(lhs, rhs, _) | ExprKind::AssignOp(_, lhs, rhs)
|
||||
if rhs.hir_id == child_id && path_to_local_id(lhs, id) =>
|
||||
if rhs.hir_id == child_id && lhs.res_local_id() == Some(id) =>
|
||||
{
|
||||
return;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::{SpanRangeExt, snippet};
|
||||
use clippy_utils::{path_to_local_id, sym};
|
||||
use clippy_utils::sym;
|
||||
use rustc_ast::{LitKind, StrStyle};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
|
|
@ -176,7 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for PathbufThenPush<'tcx> {
|
|||
if let Some(mut searcher) = self.searcher.take()
|
||||
&& let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind
|
||||
&& let ExprKind::MethodCall(name, self_arg, [arg_expr], _) = expr.kind
|
||||
&& path_to_local_id(self_arg, searcher.local_id)
|
||||
&& self_arg.res_local_id() == Some(searcher.local_id)
|
||||
&& name.ident.name == sym::push
|
||||
{
|
||||
searcher.err_span = searcher.err_span.to(stmt.span);
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ use clippy_utils::ty::{implements_trait, is_copy};
|
|||
use clippy_utils::usage::local_used_after_expr;
|
||||
use clippy_utils::{
|
||||
eq_expr_value, fn_def_id_with_node_args, higher, is_else_clause, is_in_const_context, is_lint_allowed,
|
||||
pat_and_expr_can_be_question_mark, path_to_local_id, peel_blocks, peel_blocks_with_stmt, span_contains_cfg,
|
||||
span_contains_comment, sym,
|
||||
pat_and_expr_can_be_question_mark, peel_blocks, peel_blocks_with_stmt, span_contains_cfg, span_contains_comment,
|
||||
sym,
|
||||
};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
|
||||
|
|
@ -378,7 +378,7 @@ fn check_arm_is_some_or_ok<'tcx>(cx: &LateContext<'tcx>, mode: TryMode, arm: &Ar
|
|||
// Extract out `val`
|
||||
&& let Some(binding) = extract_binding_pat(val_binding)
|
||||
// Check body is just `=> val`
|
||||
&& path_to_local_id(peel_blocks(arm.body), binding)
|
||||
&& peel_blocks(arm.body).res_local_id() == Some(binding)
|
||||
{
|
||||
true
|
||||
} else {
|
||||
|
|
@ -431,8 +431,10 @@ fn is_local_or_local_into(cx: &LateContext<'_>, expr: &Expr<'_>, val: HirId) ->
|
|||
.and_then(|(fn_def_id, _)| cx.tcx.trait_of_assoc(fn_def_id))
|
||||
.is_some_and(|trait_def_id| cx.tcx.is_diagnostic_item(sym::Into, trait_def_id));
|
||||
match expr.kind {
|
||||
ExprKind::MethodCall(_, recv, [], _) | ExprKind::Call(_, [recv]) => is_into_call && path_to_local_id(recv, val),
|
||||
_ => path_to_local_id(expr, val),
|
||||
ExprKind::MethodCall(_, recv, [], _) | ExprKind::Call(_, [recv]) => {
|
||||
is_into_call && recv.res_local_id() == Some(val)
|
||||
},
|
||||
_ => expr.res_local_id() == Some(val),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -484,7 +486,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
|
|||
if_then,
|
||||
if_else,
|
||||
)
|
||||
&& ((is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id))
|
||||
&& ((is_early_return(sym::Option, cx, &if_block) && peel_blocks(if_then).res_local_id() == Some(bind_id))
|
||||
|| is_early_return(sym::Result, cx, &if_block))
|
||||
&& if_else
|
||||
.map(|e| eq_expr_value(cx, let_expr, peel_blocks(e)))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::higher::{VecInitKind, get_vec_init_kind};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::{is_from_proc_macro, path_to_local_id, sym};
|
||||
use clippy_utils::{is_from_proc_macro, sym};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind};
|
||||
|
|
@ -125,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
|
|||
if let Some(searcher) = self.searcher.take() {
|
||||
if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind
|
||||
&& let ExprKind::MethodCall(name, self_arg, [space_hint], _) = expr.kind
|
||||
&& path_to_local_id(self_arg, searcher.local_id)
|
||||
&& self_arg.res_local_id() == Some(searcher.local_id)
|
||||
&& name.ident.name == sym::reserve
|
||||
&& !is_from_proc_macro(cx, expr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::SpanRangeExt;
|
||||
use clippy_utils::sugg::has_enclosing_paren;
|
||||
use clippy_utils::visitors::for_each_expr;
|
||||
use clippy_utils::{binary_expr_needs_parentheses, fn_def_id, path_to_local_id, span_contains_cfg};
|
||||
use clippy_utils::{binary_expr_needs_parentheses, fn_def_id, span_contains_cfg};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Block, Expr, PatKind, StmtKind};
|
||||
|
|
@ -21,7 +22,7 @@ pub(super) fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>)
|
|||
&& cx.tcx.hir_attrs(local.hir_id).is_empty()
|
||||
&& let Some(initexpr) = &local.init
|
||||
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind
|
||||
&& path_to_local_id(retexpr, local_id)
|
||||
&& retexpr.res_local_id() == Some(local_id)
|
||||
&& (cx.sess().edition() >= Edition::Edition2024 || !last_statement_borrows(cx, initexpr))
|
||||
&& !initexpr.span.in_external_macro(cx.sess().source_map())
|
||||
&& !retexpr.span.in_external_macro(cx.sess().source_map())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::path_to_local_id;
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::visitors::{Descend, Visitable, for_each_expr};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
|
|
@ -202,7 +202,7 @@ pub fn is_local_used_except<'tcx>(
|
|||
for_each_expr(cx, visitable, |e| {
|
||||
if except.is_some_and(|it| it == e.hir_id) {
|
||||
ControlFlow::Continue(Descend::No)
|
||||
} else if path_to_local_id(e, id) {
|
||||
} else if e.res_local_id() == Some(id) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
ControlFlow::Continue(Descend::Yes)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
|
|||
use clippy_utils::macros::matching_root_macro_call;
|
||||
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath};
|
||||
use clippy_utils::sugg::Sugg;
|
||||
use clippy_utils::{SpanlessEq, get_enclosing_block, is_integer_literal, path_to_local_id, span_contains_comment, sym};
|
||||
use clippy_utils::{SpanlessEq, get_enclosing_block, is_integer_literal, span_contains_comment, sym};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::{Visitor, walk_block, walk_expr, walk_stmt};
|
||||
use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, PatKind, Stmt, StmtKind};
|
||||
|
|
@ -244,7 +244,7 @@ impl<'tcx> VectorInitializationVisitor<'_, 'tcx> {
|
|||
fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.initialization_found
|
||||
&& let ExprKind::MethodCall(path, self_arg, [extend_arg], _) = expr.kind
|
||||
&& path_to_local_id(self_arg, self.vec_alloc.local_id)
|
||||
&& self_arg.res_local_id() == Some(self.vec_alloc.local_id)
|
||||
&& path.ident.name == sym::extend
|
||||
&& self.is_repeat_take(extend_arg)
|
||||
{
|
||||
|
|
@ -256,7 +256,7 @@ impl<'tcx> VectorInitializationVisitor<'_, 'tcx> {
|
|||
fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'tcx>) {
|
||||
if self.initialization_found
|
||||
&& let ExprKind::MethodCall(path, self_arg, [len_arg, fill_arg], _) = expr.kind
|
||||
&& path_to_local_id(self_arg, self.vec_alloc.local_id)
|
||||
&& self_arg.res_local_id() == Some(self.vec_alloc.local_id)
|
||||
&& path.ident.name == sym::resize
|
||||
// Check that is filled with 0
|
||||
&& is_integer_literal(fill_arg, 0)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
|
|||
use clippy_utils::eager_or_lazy::switch_to_eager_eval;
|
||||
use clippy_utils::macros::matching_root_macro_call;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::{snippet, str_literal_to_char_literal};
|
||||
use clippy_utils::sym;
|
||||
use clippy_utils::visitors::{Descend, for_each_expr};
|
||||
use clippy_utils::{path_to_local_id, sym};
|
||||
use itertools::Itertools;
|
||||
use rustc_ast::{BinOpKind, LitKind};
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -146,12 +147,12 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<
|
|||
if for_each_expr(cx, body.value, |sub_expr| -> ControlFlow<(), Descend> {
|
||||
match sub_expr.kind {
|
||||
ExprKind::Binary(op, left, right) if op.node == BinOpKind::Eq => {
|
||||
if path_to_local_id(left, binding)
|
||||
if left.res_local_id() == Some(binding)
|
||||
&& let Some(span) = get_char_span(cx, right)
|
||||
{
|
||||
set_char_spans.push(span);
|
||||
ControlFlow::Continue(Descend::No)
|
||||
} else if path_to_local_id(right, binding)
|
||||
} else if right.res_local_id() == Some(binding)
|
||||
&& let Some(span) = get_char_span(cx, left)
|
||||
{
|
||||
set_char_spans.push(span);
|
||||
|
|
@ -164,7 +165,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<
|
|||
ExprKind::Match(match_value, [arm, _], _) => {
|
||||
if matching_root_macro_call(cx, sub_expr.span, sym::matches_macro).is_none()
|
||||
|| arm.guard.is_some()
|
||||
|| !path_to_local_id(match_value, binding)
|
||||
|| match_value.res_local_id() != Some(binding)
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
|
||||
use clippy_utils::higher::{VecInitKind, get_vec_init_kind};
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::ty::is_uninit_value_valid_for_ty;
|
||||
use clippy_utils::{SpanlessEq, is_integer_literal, is_lint_allowed, path_to_local_id, peel_hir_expr_while, sym};
|
||||
use clippy_utils::{SpanlessEq, is_integer_literal, is_lint_allowed, peel_hir_expr_while, sym};
|
||||
use rustc_hir::{Block, Expr, ExprKind, HirId, PatKind, PathSegment, Stmt, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
|
|
@ -140,7 +140,7 @@ enum VecLocation<'tcx> {
|
|||
impl<'tcx> VecLocation<'tcx> {
|
||||
pub fn eq_expr(self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
|
||||
match self {
|
||||
VecLocation::Local(hir_id) => path_to_local_id(expr, hir_id),
|
||||
VecLocation::Local(hir_id) => expr.res_local_id() == Some(hir_id),
|
||||
VecLocation::Expr(self_expr) => SpanlessEq::new(cx).eq_expr(self_expr, expr),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::ty::peel_and_count_ty_refs;
|
||||
use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators, sym};
|
||||
use clippy_utils::{fn_def_id, is_trait_method, peel_ref_operators, sym};
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_hir::intravisit::{Visitor, walk_expr};
|
||||
use rustc_hir::{Block, Expr, ExprKind, HirId, LetStmt, Node, PatKind, PathSegment, StmtKind};
|
||||
|
|
@ -117,7 +117,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> {
|
||||
if path_to_local_id(ex, self.expected_hir_id) {
|
||||
if ex.res_local_id() == Some(self.expected_hir_id) {
|
||||
for (_, node) in self.cx.tcx.hir_parent_iter(ex.hir_id) {
|
||||
match node {
|
||||
Node::Expr(expr) => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::higher::{VecInitKind, get_vec_init_kind};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet;
|
||||
use clippy_utils::visitors::for_each_local_use_after_expr;
|
||||
use clippy_utils::{get_parent_expr, path_to_local_id, sym};
|
||||
use clippy_utils::{get_parent_expr, sym};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
|
|
@ -201,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush {
|
|||
if let Some(searcher) = self.searcher.take() {
|
||||
if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind
|
||||
&& let ExprKind::MethodCall(name, self_arg, [_], _) = expr.kind
|
||||
&& path_to_local_id(self_arg, searcher.local_id)
|
||||
&& self_arg.res_local_id() == Some(searcher.local_id)
|
||||
&& name.ident.name == sym::push
|
||||
{
|
||||
self.searcher = Some(VecPushSearcher {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use ControlFlow::{Break, Continue};
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::res::MaybeDef;
|
||||
use clippy_utils::{fn_def_id, get_enclosing_block, path_to_local_id};
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::{fn_def_id, get_enclosing_block};
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_ast::visit::visit_opt;
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -168,7 +168,7 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> {
|
|||
return walk_expr(self, ex);
|
||||
}
|
||||
|
||||
if path_to_local_id(ex, self.local_id) {
|
||||
if ex.res_local_id() == Some(self.local_id) {
|
||||
match self.cx.tcx.parent_hir_node(ex.hir_id) {
|
||||
Node::Stmt(Stmt {
|
||||
kind: StmtKind::Semi(_),
|
||||
|
|
|
|||
|
|
@ -430,12 +430,6 @@ pub fn qpath_generic_tys<'tcx>(qpath: &QPath<'tcx>) -> impl Iterator<Item = &'tc
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns true if the expression is a path to a local with the specified `HirId`.
|
||||
/// Use this function to see if an expression matches a function argument or a match binding.
|
||||
pub fn path_to_local_id(expr: &Expr<'_>, id: HirId) -> bool {
|
||||
expr.res_local_id() == Some(id)
|
||||
}
|
||||
|
||||
/// If the expression is a path to a local (with optional projections),
|
||||
/// returns the canonical `HirId` of the local.
|
||||
///
|
||||
|
|
@ -1599,7 +1593,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc
|
|||
.ctor_parent(cx)
|
||||
.is_lang_item(cx, ResultOk)
|
||||
&& let PatKind::Binding(_, hir_id, _, None) = pat[0].kind
|
||||
&& path_to_local_id(arm.body, hir_id)
|
||||
&& arm.body.res_local_id() == Some(hir_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1904,7 +1898,7 @@ pub fn is_expr_identity_of_pat(cx: &LateContext<'_>, pat: &Pat<'_>, expr: &Expr<
|
|||
|
||||
match (pat.kind, expr.kind) {
|
||||
(PatKind::Binding(_, id, _, _), _) if by_hir => {
|
||||
path_to_local_id(expr, id) && cx.typeck_results().expr_adjustments(expr).is_empty()
|
||||
expr.res_local_id() == Some(id) && cx.typeck_results().expr_adjustments(expr).is_empty()
|
||||
},
|
||||
(PatKind::Binding(_, _, ident, _), ExprKind::Path(QPath::Resolved(_, path))) => {
|
||||
matches!(path.segments, [ segment] if segment.ident.name == ident.name)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::macros::root_macro_call_first_node;
|
||||
use crate::res::MaybeResPath;
|
||||
use crate::visitors::{Descend, Visitable, for_each_expr, for_each_expr_without_closures};
|
||||
use crate::{self as utils, get_enclosing_loop_or_multi_call_closure};
|
||||
use core::ops::ControlFlow;
|
||||
|
|
@ -196,7 +197,7 @@ pub fn contains_return_break_continue_macro(expression: &Expr<'_>) -> bool {
|
|||
|
||||
pub fn local_used_in<'tcx>(cx: &LateContext<'tcx>, local_id: HirId, v: impl Visitable<'tcx>) -> bool {
|
||||
for_each_expr(cx, v, |e| {
|
||||
if utils::path_to_local_id(e, local_id) {
|
||||
if e.res_local_id() == Some(local_id) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
ControlFlow::Continue(())
|
||||
|
|
@ -222,7 +223,7 @@ pub fn local_used_after_expr(cx: &LateContext<'_>, local_id: HirId, after: &Expr
|
|||
let mut past_expr = false;
|
||||
for_each_expr(cx, block, |e| {
|
||||
if past_expr {
|
||||
if utils::path_to_local_id(e, local_id) {
|
||||
if e.res_local_id() == Some(local_id) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
ControlFlow::Continue(Descend::Yes)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use crate::get_enclosing_block;
|
||||
use crate::msrvs::Msrv;
|
||||
use crate::qualify_min_const_fn::is_stable_const_fn;
|
||||
use crate::res::MaybeResPath;
|
||||
use crate::ty::needs_ordered_drop;
|
||||
use crate::{get_enclosing_block, path_to_local_id};
|
||||
use core::ops::ControlFlow;
|
||||
use rustc_ast::visit::{VisitorResult, try_visit};
|
||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||
|
|
@ -312,7 +313,7 @@ pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool {
|
|||
/// Checks if the given local is used.
|
||||
pub fn is_local_used<'tcx>(cx: &LateContext<'tcx>, visitable: impl Visitable<'tcx>, id: HirId) -> bool {
|
||||
for_each_expr(cx, visitable, |e| {
|
||||
if path_to_local_id(e, id) {
|
||||
if e.res_local_id() == Some(id) {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
ControlFlow::Continue(())
|
||||
|
|
@ -564,7 +565,7 @@ pub fn for_each_local_use_after_expr<'tcx, B>(
|
|||
if self.res.is_break() {
|
||||
return;
|
||||
}
|
||||
if path_to_local_id(e, self.local_id) {
|
||||
if e.res_local_id() == Some(self.local_id) {
|
||||
self.res = (self.f)(e);
|
||||
} else {
|
||||
walk_expr(self, e);
|
||||
|
|
@ -740,7 +741,7 @@ pub fn for_each_local_assignment<'tcx, B>(
|
|||
fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) {
|
||||
if let ExprKind::Assign(lhs, rhs, _) = e.kind
|
||||
&& self.res.is_continue()
|
||||
&& path_to_local_id(lhs, self.local_id)
|
||||
&& lhs.res_local_id() == Some(self.local_id)
|
||||
{
|
||||
self.res = (self.f)(rhs);
|
||||
self.visit_expr(rhs);
|
||||
|
|
@ -785,7 +786,7 @@ pub fn local_used_once<'tcx>(
|
|||
let mut expr = None;
|
||||
|
||||
let cf = for_each_expr(cx, visitable, |e| {
|
||||
if path_to_local_id(e, id) && expr.replace(e).is_some() {
|
||||
if e.res_local_id() == Some(id) && expr.replace(e).is_some() {
|
||||
ControlFlow::Break(())
|
||||
} else {
|
||||
ControlFlow::Continue(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue