Skip to content

Commit a6078f8

Browse files
committed
Remove path_to_local_id
1 parent 53675ce commit a6078f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+150
-145
lines changed

clippy_lints/src/collection_is_never_read.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::res::MaybeDef;
2+
use clippy_utils::get_enclosing_block;
3+
use clippy_utils::res::{MaybeDef, MaybeResPath};
34
use clippy_utils::visitors::{Visitable, for_each_expr};
4-
use clippy_utils::{get_enclosing_block, path_to_local_id};
55
use core::ops::ControlFlow;
66
use rustc_hir::{Body, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
77
use rustc_lint::{LateContext, LateLintPass};
@@ -81,7 +81,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
8181
// Inspect all expressions and sub-expressions in the block.
8282
for_each_expr(cx, block, |expr| {
8383
// Ignore expressions that are not simply `id`.
84-
if !path_to_local_id(expr, id) {
84+
if expr.res_local_id() != Some(id) {
8585
return ControlFlow::Continue(());
8686
}
8787

@@ -93,7 +93,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
9393
// id = ...; // Not reading `id`.
9494
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
9595
&& let ExprKind::Assign(lhs, ..) = parent.kind
96-
&& path_to_local_id(lhs, id)
96+
&& lhs.res_local_id() == Some(id)
9797
{
9898
return ControlFlow::Continue(());
9999
}
@@ -107,7 +107,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
107107
// have side effects, so consider them a read.
108108
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
109109
&& let ExprKind::MethodCall(_, receiver, args, _) = parent.kind
110-
&& path_to_local_id(receiver, id)
110+
&& receiver.res_local_id() == Some(id)
111111
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
112112
&& !method_def_id.is_local()
113113
{

clippy_lints/src/eta_reduction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::higher::VecArgs;
33
use clippy_utils::res::{MaybeDef, MaybeResPath};
44
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
55
use clippy_utils::usage::{local_used_after_expr, local_used_in};
6-
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local_id};
6+
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate};
77
use rustc_abi::ExternAbi;
88
use rustc_errors::Applicability;
99
use rustc_hir::attrs::AttributeKind;
@@ -305,7 +305,7 @@ fn check_inputs(
305305
matches!(
306306
p.pat.kind,
307307
PatKind::Binding(BindingMode::NONE, id, _, None)
308-
if path_to_local_id(arg, id)
308+
if arg.res_local_id() == Some(id)
309309
)
310310
// Only allow adjustments which change regions (i.e. re-borrowing).
311311
&& typeck

clippy_lints/src/let_if_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
2-
use clippy_utils::path_to_local_id;
2+
use clippy_utils::res::MaybeResPath;
33
use clippy_utils::source::snippet;
44
use clippy_utils::visitors::is_local_used;
55
use rustc_errors::Applicability;
@@ -145,7 +145,7 @@ fn check_assign<'tcx>(
145145
&& let Some(expr) = block.stmts.iter().last()
146146
&& let hir::StmtKind::Semi(expr) = expr.kind
147147
&& let hir::ExprKind::Assign(var, value, _) = expr.kind
148-
&& path_to_local_id(var, decl)
148+
&& var.res_local_id() == Some(decl)
149149
{
150150
if block
151151
.stmts

clippy_lints/src/lines_filter_map_ok.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::msrvs::{self, Msrv};
4-
use clippy_utils::res::MaybeDef;
5-
use clippy_utils::{is_diag_item_method, is_trait_method, path_to_local_id, sym};
4+
use clippy_utils::res::{MaybeDef, MaybeResPath};
5+
use clippy_utils::{is_diag_item_method, is_trait_method, sym};
66
use rustc_errors::Applicability;
77
use rustc_hir::{Body, Closure, Expr, ExprKind};
88
use rustc_lint::{LateContext, LateLintPass};
@@ -120,7 +120,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_name: Symbol) ->
120120
params: [param], value, ..
121121
} = cx.tcx.hir_body(*body)
122122
&& let ExprKind::MethodCall(method, receiver, [], _) = value.kind
123-
&& path_to_local_id(receiver, param.pat.hir_id)
123+
&& receiver.res_local_id() == Some(param.pat.hir_id)
124124
&& let Some(method_did) = cx.typeck_results().type_dependent_def_id(value.hir_id)
125125
{
126126
is_diag_item_method(cx, method_did, sym::Result) && method.ident.name == sym::ok

clippy_lints/src/loops/char_indices_as_byte_indices.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::ops::ControlFlow;
22

33
use clippy_utils::diagnostics::span_lint_hir_and_then;
4-
use clippy_utils::res::MaybeDef;
4+
use clippy_utils::res::{MaybeDef, MaybeResPath};
55
use clippy_utils::visitors::for_each_expr;
6-
use clippy_utils::{eq_expr_value, higher, path_to_local_id, sym};
6+
use clippy_utils::{eq_expr_value, higher, sym};
77
use rustc_errors::{Applicability, MultiSpan};
88
use rustc_hir::{Expr, ExprKind, LangItem, Node, Pat, PatKind};
99
use rustc_lint::LateContext;
@@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, iterable: &Expr
4949
{
5050
// Destructured iterator element `(idx, _)`, look for uses of the binding
5151
for_each_expr(cx, body, |expr| {
52-
if path_to_local_id(expr, binding_id) {
52+
if expr.res_local_id() == Some(binding_id) {
5353
check_index_usage(cx, expr, pat, enumerate_span, chars_span, chars_recv);
5454
}
5555
CONTINUE
@@ -58,7 +58,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, iterable: &Expr
5858
// Bound as a tuple, look for `tup.0`
5959
for_each_expr(cx, body, |expr| {
6060
if let ExprKind::Field(e, field) = expr.kind
61-
&& path_to_local_id(e, binding_id)
61+
&& e.res_local_id() == Some(binding_id)
6262
&& field.name == sym::integer(0)
6363
{
6464
check_index_usage(cx, expr, pat, enumerate_span, chars_span, chars_recv);

clippy_lints/src/loops/manual_flatten.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use super::MANUAL_FLATTEN;
22
use super::utils::make_iterator_snippet;
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::msrvs::{self, Msrv};
5+
use clippy_utils::res::MaybeResPath;
56
use clippy_utils::source::{HasSession, indent_of, reindent_multiline, snippet_with_applicability};
67
use clippy_utils::visitors::is_local_used;
7-
use clippy_utils::{higher, is_refutable, path_to_local_id, peel_blocks_with_stmt, span_contains_comment};
8+
use clippy_utils::{higher, is_refutable, peel_blocks_with_stmt, span_contains_comment};
89
use rustc_errors::Applicability;
910
use rustc_hir::def::{DefKind, Res};
1011
use rustc_hir::{Expr, Pat, PatKind};
@@ -27,7 +28,7 @@ pub(super) fn check<'tcx>(
2728
= higher::IfLet::hir(cx, inner_expr)
2829
// Ensure match_expr in `if let` statement is the same as the pat from the for-loop
2930
&& let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind
30-
&& path_to_local_id(let_expr, pat_hir_id)
31+
&& let_expr.res_local_id() == Some(pat_hir_id)
3132
// Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result`
3233
&& let PatKind::TupleStruct(ref qpath, [inner_pat], _) = let_pat.kind
3334
&& let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(qpath, let_pat.hir_id)

clippy_lints/src/loops/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::res::MaybeResPath;
22
use clippy_utils::ty::{has_iter_method, implements_trait};
3-
use clippy_utils::{get_parent_expr, is_integer_const, path_to_local_id, sugg};
3+
use clippy_utils::{get_parent_expr, is_integer_const, sugg};
44
use rustc_ast::ast::{LitIntType, LitKind};
55
use rustc_errors::Applicability;
66
use rustc_hir::intravisit::{Visitor, walk_expr, walk_local};
@@ -176,7 +176,7 @@ impl<'tcx> Visitor<'tcx> for InitializeVisitor<'_, 'tcx> {
176176
}
177177

178178
// If node is the desired variable, see how it's used
179-
if path_to_local_id(expr, self.var_id) {
179+
if expr.res_local_id() == Some(self.var_id) {
180180
if self.past_loop {
181181
self.state = InitializeVisitorState::DontWarn;
182182
return;

clippy_lints/src/manual_clamp.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use clippy_utils::sugg::Sugg;
88
use clippy_utils::ty::implements_trait;
99
use clippy_utils::visitors::is_const_evaluatable;
1010
use clippy_utils::{
11-
eq_expr_value, is_diag_trait_item, is_in_const_context, is_trait_method, path_to_local_id, peel_blocks,
12-
peel_blocks_with_stmt, sym,
11+
eq_expr_value, is_diag_trait_item, is_in_const_context, is_trait_method, peel_blocks, peel_blocks_with_stmt, sym,
1312
};
1413
use itertools::Itertools;
1514
use rustc_errors::{Applicability, Diag};
@@ -436,7 +435,7 @@ fn is_match_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opt
436435
let first = BinaryOp::new(first)?;
437436
let second = BinaryOp::new(second)?;
438437
if let PatKind::Binding(_, binding, _, None) = &last_arm.pat.kind
439-
&& path_to_local_id(peel_blocks_with_stmt(last_arm.body), *binding)
438+
&& peel_blocks_with_stmt(last_arm.body).res_local_id() == Some(*binding)
440439
&& last_arm.guard.is_none()
441440
{
442441
// Proceed as normal
@@ -656,8 +655,8 @@ fn is_clamp_meta_pattern<'tcx>(
656655
let (min, max) = (second_expr, first_expr);
657656
let refers_to_input = match input_hir_ids {
658657
Some((first_hir_id, second_hir_id)) => {
659-
path_to_local_id(peel_blocks(first_bin.left), first_hir_id)
660-
&& path_to_local_id(peel_blocks(second_bin.left), second_hir_id)
658+
peel_blocks(first_bin.left).res_local_id() == Some(first_hir_id)
659+
&& peel_blocks(second_bin.left).res_local_id() == Some(second_hir_id)
661660
},
662661
None => eq_expr_value(cx, first_bin.left, second_bin.left),
663662
};

clippy_lints/src/manual_hash_one.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_hir_and_then;
33
use clippy_utils::msrvs::{self, Msrv};
4+
use clippy_utils::res::MaybeResPath;
45
use clippy_utils::source::SpanRangeExt;
56
use clippy_utils::visitors::{is_local_used, local_used_once};
6-
use clippy_utils::{is_trait_method, path_to_local_id, sym};
7+
use clippy_utils::{is_trait_method, sym};
78
use rustc_errors::Applicability;
89
use rustc_hir::{BindingMode, ExprKind, LetStmt, Node, PatKind, StmtKind};
910
use rustc_lint::{LateContext, LateLintPass};
@@ -82,7 +83,7 @@ impl LateLintPass<'_> for ManualHashOne {
8283
&& let ExprKind::MethodCall(seg, hashed_value, [ref_to_hasher], _) = hash_expr.kind
8384
&& seg.ident.name == sym::hash
8485
&& is_trait_method(cx, hash_expr, sym::Hash)
85-
&& path_to_local_id(ref_to_hasher.peel_borrows(), hasher)
86+
&& ref_to_hasher.peel_borrows().res_local_id() == Some(hasher)
8687

8788
&& let maybe_finish_stmt = stmts.next()
8889
// There should be no more statements referencing `hasher`

clippy_lints/src/matches/infallible_destructuring_match.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::res::MaybeResPath;
23
use clippy_utils::source::snippet_with_applicability;
3-
use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
4+
use clippy_utils::{peel_blocks, strip_pat_refs};
45
use rustc_errors::Applicability;
56
use rustc_hir::{ExprKind, LetStmt, MatchSource, PatKind, QPath};
67
use rustc_lint::LateContext;
@@ -17,7 +18,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool {
1718
&& args.len() == 1
1819
&& let PatKind::Binding(binding, arg, ..) = strip_pat_refs(&args[0]).kind
1920
&& let body = peel_blocks(arms[0].body)
20-
&& path_to_local_id(body, arg)
21+
&& body.res_local_id() == Some(arg)
2122
{
2223
let mut applicability = Applicability::MachineApplicable;
2324
span_lint_and_sugg(

0 commit comments

Comments
 (0)