Skip to content

Commit 53675ce

Browse files
committed
Remove path_to_local
1 parent 3f686a0 commit 53675ce

40 files changed

+133
-129
lines changed

clippy_lints/src/assigning_clones.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::mir::{PossibleBorrowerMap, enclosing_mir};
44
use clippy_utils::msrvs::{self, Msrv};
5+
use clippy_utils::res::MaybeResPath;
56
use clippy_utils::sugg::Sugg;
6-
use clippy_utils::{is_diag_trait_item, is_in_test, last_path_segment, local_is_initialized, path_to_local, sym};
7+
use clippy_utils::{is_diag_trait_item, is_in_test, last_path_segment, local_is_initialized, sym};
78
use rustc_errors::Applicability;
89
use rustc_hir::{self as hir, Expr, ExprKind};
910
use rustc_lint::{LateContext, LateLintPass};
@@ -97,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
9798
// TODO: This check currently bails if the local variable has no initializer.
9899
// That is overly conservative - the lint should fire even if there was no initializer,
99100
// but the variable has been initialized before `lhs` was evaluated.
100-
&& path_to_local(lhs).is_none_or(|lhs| local_is_initialized(cx, lhs))
101+
&& lhs.res_local_id().is_none_or(|lhs| local_is_initialized(cx, lhs))
101102
&& let Some(resolved_impl) = cx.tcx.impl_of_assoc(resolved_fn.def_id())
102103
// Derived forms don't implement `clone_from`/`clone_into`.
103104
// See https://github.com/rust-lang/rust/pull/98445#issuecomment-1190681305

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::numeric_literal::NumericLiteral;
3+
use clippy_utils::res::MaybeResPath;
34
use clippy_utils::source::{SpanRangeExt, snippet_opt};
45
use clippy_utils::visitors::{Visitable, for_each_expr_without_closures};
5-
use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, is_ty_alias, path_to_local};
6+
use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, is_ty_alias};
67
use rustc_ast::{LitFloatType, LitIntType, LitKind};
78
use rustc_errors::Applicability;
89
use rustc_hir::def::{DefKind, Res};
@@ -167,11 +168,11 @@ pub(super) fn check<'tcx>(
167168
sym::assert_ne_macro,
168169
sym::debug_assert_ne_macro,
169170
];
170-
matches!(expr.span.ctxt().outer_expn_data().macro_def_id, Some(def_id) if
171+
matches!(expr.span.ctxt().outer_expn_data().macro_def_id, Some(def_id) if
171172
cx.tcx.get_diagnostic_name(def_id).is_some_and(|sym| ALLOWED_MACROS.contains(&sym)))
172173
}
173174

174-
if let Some(id) = path_to_local(cast_expr)
175+
if let Some(id) = cast_expr.res_local_id()
175176
&& !cx.tcx.hir_span(id).eq_ctxt(cast_expr.span)
176177
{
177178
// Binding context is different than the identifiers context.

clippy_lints/src/dereference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
2+
use clippy_utils::res::MaybeResPath;
23
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
34
use clippy_utils::sugg::has_enclosing_paren;
45
use clippy_utils::ty::{adjust_derefs_manually_drop, implements_trait, is_manually_drop, peel_and_count_ty_refs};
56
use clippy_utils::{
67
DefinedTy, ExprUseNode, expr_use_ctxt, get_parent_expr, is_block_like, is_from_proc_macro, is_lint_allowed,
7-
path_to_local,
88
};
99
use rustc_ast::util::parser::ExprPrecedence;
1010
use rustc_data_structures::fx::FxIndexMap;
@@ -239,7 +239,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
239239
return;
240240
}
241241

242-
if let Some(local) = path_to_local(expr) {
242+
if let Some(local) = expr.res_local_id() {
243243
self.check_local_usage(cx, expr, local);
244244
}
245245

clippy_lints/src/eta_reduction.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::higher::VecArgs;
3-
use clippy_utils::res::MaybeDef;
3+
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::{
7-
get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local, path_to_local_id,
8-
};
6+
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local_id};
97
use rustc_abi::ExternAbi;
108
use rustc_errors::Applicability;
119
use rustc_hir::attrs::AttributeKind;
@@ -218,7 +216,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
218216
"redundant closure",
219217
|diag| {
220218
if let Some(mut snippet) = snippet_opt(cx, callee.span) {
221-
if path_to_local(callee).is_some_and(|l| {
219+
if callee.res_local_id().is_some_and(|l| {
222220
// FIXME: Do we really need this `local_used_in` check?
223221
// Isn't it checking something like... `callee(callee)`?
224222
// If somehow this check is needed, add some test for it,

clippy_lints/src/format_impl.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, span_lint_and_sugg};
22
use clippy_utils::macros::{FormatArgsStorage, find_format_arg_expr, is_format_macro, root_macro_call_first_node};
3-
use clippy_utils::{get_parent_as_impl, is_diag_trait_item, path_to_local, peel_ref_operators, sym};
3+
use clippy_utils::res::MaybeResPath;
4+
use clippy_utils::{get_parent_as_impl, is_diag_trait_item, peel_ref_operators, sym};
45
use rustc_ast::{FormatArgsPiece, FormatTrait};
56
use rustc_errors::Applicability;
67
use rustc_hir::{Expr, ExprKind, Impl, ImplItem, ImplItemKind, QPath};
@@ -210,7 +211,7 @@ impl FormatImplExpr<'_, '_> {
210211
// Since the argument to fmt is itself a reference: &self
211212
let reference = peel_ref_operators(self.cx, arg);
212213
// Is the reference self?
213-
if path_to_local(reference).map(|x| self.cx.tcx.hir_name(x)) == Some(kw::SelfLower) {
214+
if reference.res_local_id().map(|x| self.cx.tcx.hir_name(x)) == Some(kw::SelfLower) {
214215
let FormatTraitNames { name, .. } = self.format_trait_impl;
215216
span_lint(
216217
self.cx,

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use clippy_utils::res::MaybeResPath;
12
use rustc_hir::{self as hir, HirId, HirIdSet, intravisit};
23
use rustc_lint::LateContext;
34
use rustc_middle::ty;
45
use rustc_span::def_id::LocalDefId;
56

67
use clippy_utils::diagnostics::span_lint;
8+
use clippy_utils::iter_input_pats;
79
use clippy_utils::ty::is_unsafe_fn;
810
use clippy_utils::visitors::for_each_expr;
9-
use clippy_utils::{iter_input_pats, path_to_local};
1011

1112
use core::ops::ControlFlow;
1213

@@ -87,7 +88,7 @@ fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
8788
}
8889

8990
fn check_arg(cx: &LateContext<'_>, raw_ptrs: &HirIdSet, arg: &hir::Expr<'_>) {
90-
if path_to_local(arg).is_some_and(|id| raw_ptrs.contains(&id)) {
91+
if arg.res_local_id().is_some_and(|id| raw_ptrs.contains(&id)) {
9192
span_lint(
9293
cx,
9394
NOT_UNSAFE_PTR_ARG_DEREF,

clippy_lints/src/ifs/branches_sharing_code.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2+
use clippy_utils::res::MaybeResPath;
23
use clippy_utils::source::{IntoSpan, SpanRangeExt, first_line_of_span, indent_of, reindent_multiline, snippet};
34
use clippy_utils::ty::needs_ordered_drop;
45
use clippy_utils::visitors::for_each_expr_without_closures;
56
use clippy_utils::{
67
ContainsName, HirEqInterExpr, SpanlessEq, capture_local_usage, get_enclosing_block, hash_expr, hash_stmt,
7-
path_to_local,
88
};
99
use core::iter;
1010
use core::ops::ControlFlow;
@@ -149,7 +149,7 @@ fn eq_binding_names(s: &Stmt<'_>, names: &[(HirId, Symbol)]) -> bool {
149149
/// Checks if the statement modifies or moves any of the given locals.
150150
fn modifies_any_local<'tcx>(cx: &LateContext<'tcx>, s: &'tcx Stmt<'_>, locals: &HirIdSet) -> bool {
151151
for_each_expr_without_closures(s, |e| {
152-
if let Some(id) = path_to_local(e)
152+
if let Some(id) = e.res_local_id()
153153
&& locals.contains(&id)
154154
&& !capture_local_usage(cx, e).is_imm_ref()
155155
{
@@ -198,7 +198,7 @@ fn scan_block_for_eq<'tcx>(
198198
let mut cond_locals = HirIdSet::default();
199199
for &cond in conds {
200200
let _: Option<!> = for_each_expr_without_closures(cond, |e| {
201-
if let Some(id) = path_to_local(e) {
201+
if let Some(id) = e.res_local_id() {
202202
cond_locals.insert(id);
203203
}
204204
ControlFlow::Continue(())

clippy_lints/src/ifs/ifs_same_cond.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;
2+
use clippy_utils::res::MaybeResPath;
23
use clippy_utils::ty::InteriorMut;
3-
use clippy_utils::{SpanlessEq, eq_expr_value, find_binding_init, hash_expr, path_to_local, search_same};
4+
use clippy_utils::{SpanlessEq, eq_expr_value, find_binding_init, hash_expr, search_same};
45
use rustc_hir::{Expr, ExprKind};
56
use rustc_lint::LateContext;
67

@@ -16,7 +17,7 @@ fn method_caller_is_mutable<'tcx>(
1617
interior_mut.is_interior_mut_ty(cx, caller_ty)
1718
|| caller_ty.is_mutable_ptr()
1819
// `find_binding_init` will return the binding iff its not mutable
19-
|| path_to_local(caller_expr)
20+
|| caller_expr.res_local_id()
2021
.and_then(|hid| find_binding_init(cx, hid))
2122
.is_none()
2223
}

clippy_lints/src/index_refutable_slice.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use clippy_config::Conf;
22
use clippy_utils::consts::{ConstEvalCtxt, Constant};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::higher::IfLet;
5+
use clippy_utils::is_lint_allowed;
56
use clippy_utils::msrvs::{self, Msrv};
7+
use clippy_utils::res::MaybeResPath;
68
use clippy_utils::ty::is_copy;
7-
use clippy_utils::{is_lint_allowed, path_to_local};
89
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
910
use rustc_errors::Applicability;
1011
use rustc_hir as hir;
@@ -225,7 +226,7 @@ impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
225226
}
226227

227228
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
228-
if let Some(local_id) = path_to_local(expr) {
229+
if let Some(local_id) = expr.res_local_id() {
229230
let Self {
230231
cx,
231232
ref mut slice_lint_info,

clippy_lints/src/loops/manual_memcpy.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use super::{IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
3+
use clippy_utils::res::MaybeResPath;
34
use clippy_utils::source::snippet;
45
use clippy_utils::sugg::Sugg;
56
use clippy_utils::ty::is_copy;
67
use clippy_utils::usage::local_used_in;
7-
use clippy_utils::{get_enclosing_block, higher, path_to_local, sugg};
8+
use clippy_utils::{get_enclosing_block, higher, sugg};
89
use rustc_ast::ast;
910
use rustc_errors::Applicability;
1011
use rustc_hir::intravisit::walk_block;
@@ -67,7 +68,7 @@ pub(super) fn check<'tcx>(
6768
&& !local_used_in(cx, canonical_id, base_left)
6869
&& !local_used_in(cx, canonical_id, base_right)
6970
// Source and destination must be different
70-
&& path_to_local(base_left) != path_to_local(base_right)
71+
&& base_left.res_local_id() != base_right.res_local_id()
7172
{
7273
Some((
7374
ty,
@@ -128,7 +129,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
128129
let print_limit = |end: &Expr<'_>, end_str: &str, base: &Expr<'_>, sugg: MinifyingSugg<'static>| {
129130
if let ExprKind::MethodCall(method, recv, [], _) = end.kind
130131
&& method.ident.name == sym::len
131-
&& path_to_local(recv) == path_to_local(base)
132+
&& recv.res_local_id() == base.res_local_id()
132133
{
133134
if sugg.to_string() == end_str {
134135
sugg::EMPTY.into()
@@ -364,7 +365,7 @@ fn get_details_from_idx<'tcx>(
364365
starts: &[Start<'tcx>],
365366
) -> Option<(StartKind<'tcx>, Offset)> {
366367
fn get_start<'tcx>(e: &Expr<'_>, starts: &[Start<'tcx>]) -> Option<StartKind<'tcx>> {
367-
let id = path_to_local(e)?;
368+
let id = e.res_local_id()?;
368369
starts.iter().find(|start| start.id == id).map(|start| start.kind)
369370
}
370371

@@ -425,7 +426,7 @@ fn get_assignments<'a, 'tcx>(
425426
.chain(*expr)
426427
.filter(move |e| {
427428
if let ExprKind::AssignOp(_, place, _) = e.kind {
428-
path_to_local(place).is_some_and(|id| {
429+
place.res_local_id().is_some_and(|id| {
429430
!loop_counters
430431
.iter()
431432
// skip the first item which should be `StartKind::Range`

0 commit comments

Comments
 (0)