Skip to content

Commit 5b659ba

Browse files
committed
Remove path_res
1 parent 53783de commit 5b659ba

34 files changed

+119
-122
lines changed

clippy_lints/src/assertions_on_result_states.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;
22
use clippy_utils::macros::{PanicExpn, find_assert_args, root_macro_call_first_node};
3-
use clippy_utils::res::MaybeDef;
3+
use clippy_utils::res::{MaybeDef, MaybeResPath};
44
use clippy_utils::source::snippet_with_context;
5+
use clippy_utils::sym;
56
use clippy_utils::ty::{has_debug_impl, is_copy};
67
use clippy_utils::usage::local_used_after_expr;
7-
use clippy_utils::{path_res, sym};
88
use rustc_errors::Applicability;
99
use rustc_hir::def::Res;
1010
use rustc_hir::{Expr, ExprKind, Node};
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
6262
if !is_copy(cx, result_type) {
6363
if result_type_with_refs != result_type {
6464
return;
65-
} else if let Res::Local(binding_id) = path_res(cx, recv)
65+
} else if let Res::Local(binding_id) = *recv.basic_res()
6666
&& local_used_after_expr(cx, binding_id, recv)
6767
{
6868
return;

clippy_lints/src/derive/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::path_res;
1+
use clippy_utils::res::MaybeResPath;
22
use rustc_hir::def::Res;
33
use rustc_hir::{Impl, Item, ItemKind};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
199199
self_ty,
200200
..
201201
}) = item.kind
202-
&& let Res::Def(_, def_id) = path_res(cx, self_ty)
202+
&& let Res::Def(_, def_id) = *self_ty.basic_res()
203203
&& let Some(local_def_id) = def_id.as_local()
204204
{
205205
let adt_hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);

clippy_lints/src/error_impl_error.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, span_lint_hir_and_then};
2-
use clippy_utils::path_res;
2+
use clippy_utils::res::MaybeResPath;
33
use clippy_utils::ty::implements_trait;
44
use rustc_hir::def_id::{DefId, LocalDefId};
55
use rustc_hir::{Item, ItemKind};
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError {
5555
if let Some(trait_def_id) = imp.of_trait.and_then(|t| t.trait_ref.trait_def_id())
5656
&& let Some(error_def_id) = cx.tcx.get_diagnostic_item(sym::Error)
5757
&& error_def_id == trait_def_id
58-
&& let Some(def_id) = path_res(cx, imp.self_ty).opt_def_id().and_then(DefId::as_local)
58+
&& let Some(def_id) = imp.self_ty.basic_res().opt_def_id().and_then(DefId::as_local)
5959
&& let Some(ident) = cx.tcx.opt_item_ident(def_id.to_def_id())
6060
&& ident.name == sym::Error
6161
&& is_visible_outside_module(cx, def_id) =>

clippy_lints/src/if_then_some_else_none.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::eager_or_lazy::switch_to_eager_eval;
44
use clippy_utils::msrvs::{self, Msrv};
5+
use clippy_utils::res::MaybeQPath;
56
use clippy_utils::source::{snippet_with_applicability, snippet_with_context, walk_span_to_context};
67
use clippy_utils::sugg::Sugg;
78
use clippy_utils::{
89
contains_return, expr_adjustment_requires_coercion, higher, is_else_clause, is_in_const_context, is_res_lang_ctor,
9-
path_res, peel_blocks, sym,
10+
peel_blocks, sym,
1011
};
1112
use rustc_errors::Applicability;
1213
use rustc_hir::LangItem::{OptionNone, OptionSome};
@@ -73,8 +74,8 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
7374
&& let ExprKind::Call(then_call, [then_arg]) = then_expr.kind
7475
&& !expr.span.from_expansion()
7576
&& !then_expr.span.from_expansion()
76-
&& is_res_lang_ctor(cx, path_res(cx, then_call), OptionSome)
77-
&& is_res_lang_ctor(cx, path_res(cx, peel_blocks(els)), OptionNone)
77+
&& is_res_lang_ctor(cx, then_call.res(cx), OptionSome)
78+
&& is_res_lang_ctor(cx, peel_blocks(els).res(cx), OptionNone)
7879
&& !is_else_clause(cx.tcx, expr)
7980
&& !is_in_const_context(cx)
8081
&& self.msrv.meets(cx, msrvs::BOOL_THEN)

clippy_lints/src/loops/manual_find.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::MANUAL_FIND;
22
use super::utils::make_iterator_snippet;
33
use clippy_utils::diagnostics::span_lint_and_then;
4+
use clippy_utils::res::{MaybeQPath, MaybeResPath};
45
use clippy_utils::source::snippet_with_applicability;
56
use clippy_utils::ty::implements_trait;
67
use clippy_utils::usage::contains_return_break_continue_macro;
7-
use clippy_utils::{higher, is_res_lang_ctor, path_res, peel_blocks_with_stmt};
8+
use clippy_utils::{higher, is_res_lang_ctor, peel_blocks_with_stmt};
89
use rustc_errors::Applicability;
9-
use rustc_hir::def::Res;
1010
use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, Node, Pat, PatKind, Stmt, StmtKind};
1212
use rustc_lint::LateContext;
@@ -34,8 +34,8 @@ pub(super) fn check<'tcx>(
3434
&& let StmtKind::Semi(semi) = stmt.kind
3535
&& let ExprKind::Ret(Some(ret_value)) = semi.kind
3636
&& let ExprKind::Call(ctor, [inner_ret]) = ret_value.kind
37-
&& is_res_lang_ctor(cx, path_res(cx, ctor), LangItem::OptionSome)
38-
&& path_res(cx, inner_ret) == Res::Local(binding_id)
37+
&& is_res_lang_ctor(cx, ctor.res(cx), LangItem::OptionSome)
38+
&& inner_ret.res_local_id() == Some(binding_id)
3939
&& !contains_return_break_continue_macro(cond)
4040
&& let Some((last_stmt, last_ret)) = last_stmt_and_ret(cx, expr)
4141
{
@@ -150,7 +150,7 @@ fn last_stmt_and_ret<'tcx>(
150150
&& let Some((_, Node::Block(block))) = parent_iter.next()
151151
&& let Some((last_stmt, last_ret)) = extract(block)
152152
&& last_stmt.hir_id == node_hir
153-
&& is_res_lang_ctor(cx, path_res(cx, last_ret), LangItem::OptionNone)
153+
&& is_res_lang_ctor(cx, last_ret.res(cx), LangItem::OptionNone)
154154
&& let Some((_, Node::Expr(_block))) = parent_iter.next()
155155
// This includes the function header
156156
&& let Some((_, func)) = parent_iter.next()

clippy_lints/src/manual_clamp.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant};
33
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
44
use clippy_utils::higher::If;
55
use clippy_utils::msrvs::{self, Msrv};
6+
use clippy_utils::res::MaybeResPath;
67
use clippy_utils::sugg::Sugg;
78
use clippy_utils::ty::implements_trait;
89
use clippy_utils::visitors::is_const_evaluatable;
910
use clippy_utils::{
10-
eq_expr_value, is_diag_trait_item, is_in_const_context, is_trait_method, path_res, path_to_local_id, peel_blocks,
11+
eq_expr_value, is_diag_trait_item, is_in_const_context, is_trait_method, path_to_local_id, peel_blocks,
1112
peel_blocks_with_stmt, sym,
1213
};
1314
use itertools::Itertools;
@@ -342,7 +343,7 @@ fn is_call_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
342343
}
343344
},
344345
ExprKind::Path(QPath::TypeRelative(ty, seg)) => {
345-
matches!(path_res(cx, ty), Res::PrimTy(PrimTy::Float(_))).then(|| FunctionType::OrdOrFloat(seg))
346+
matches!(ty.basic_res(), Res::PrimTy(PrimTy::Float(_))).then(|| FunctionType::OrdOrFloat(seg))
346347
},
347348
_ => None,
348349
}

clippy_lints/src/matches/manual_filter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::res::MaybeDef;
2+
use clippy_utils::res::{MaybeDef, MaybeQPath};
33
use clippy_utils::visitors::contains_unsafe_block;
4-
use clippy_utils::{is_res_lang_ctor, path_res, path_to_local_id};
4+
use clippy_utils::{is_res_lang_ctor, path_to_local_id};
55

66
use rustc_hir::LangItem::{OptionNone, OptionSome};
77
use rustc_hir::{Arm, Expr, ExprKind, HirId, Pat, PatKind};
@@ -66,15 +66,15 @@ fn is_some_expr(cx: &LateContext<'_>, target: HirId, ctxt: SyntaxContext, expr:
6666
&& let ExprKind::Call(callee, [arg]) = inner_expr.kind
6767
{
6868
return ctxt == expr.span.ctxt()
69-
&& is_res_lang_ctor(cx, path_res(cx, callee), OptionSome)
69+
&& is_res_lang_ctor(cx, callee.res(cx), OptionSome)
7070
&& path_to_local_id(arg, target);
7171
}
7272
false
7373
}
7474

7575
fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
7676
if let Some(inner_expr) = peels_blocks_incl_unsafe_opt(expr) {
77-
return is_res_lang_ctor(cx, path_res(cx, inner_expr), OptionNone);
77+
return is_res_lang_ctor(cx, inner_expr.res(cx), OptionNone);
7878
}
7979
false
8080
}

clippy_lints/src/matches/manual_map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use super::MANUAL_MAP;
22
use super::manual_utils::{SomeExpr, check_with};
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44

5-
use clippy_utils::{is_res_lang_ctor, path_res};
5+
use clippy_utils::is_res_lang_ctor;
66

7+
use clippy_utils::res::MaybeQPath;
78
use rustc_hir::LangItem::OptionSome;
89
use rustc_hir::{Arm, Block, BlockCheckMode, Expr, ExprKind, Pat, UnsafeSource};
910
use rustc_lint::LateContext;
@@ -91,7 +92,7 @@ fn get_some_expr<'tcx>(
9192
// TODO: Allow more complex expressions.
9293
match expr.kind {
9394
ExprKind::Call(callee, [arg])
94-
if ctxt == expr.span.ctxt() && is_res_lang_ctor(cx, path_res(cx, callee), OptionSome) =>
95+
if ctxt == expr.span.ctxt() && is_res_lang_ctor(cx, callee.res(cx), OptionSome) =>
9596
{
9697
Some(SomeExpr::new_no_negated(arg, needs_unsafe_block))
9798
},

clippy_lints/src/matches/manual_ok_err.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;
2+
use clippy_utils::res::MaybeQPath;
23
use clippy_utils::source::{indent_of, reindent_multiline};
34
use clippy_utils::sugg::Sugg;
45
use clippy_utils::ty::{option_arg_ty, peel_and_count_ty_refs};
5-
use clippy_utils::{get_parent_expr, is_res_lang_ctor, path_res, peel_blocks, span_contains_comment};
6+
use clippy_utils::{get_parent_expr, is_res_lang_ctor, peel_blocks, span_contains_comment};
67
use rustc_ast::{BindingMode, Mutability};
78
use rustc_errors::Applicability;
89
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr};
@@ -103,7 +104,7 @@ fn is_ok_or_err<'hir>(cx: &LateContext<'_>, pat: &Pat<'hir>) -> Option<(bool, &'
103104
/// Check if `expr` contains `Some(ident)`, possibly as a block
104105
fn is_some_ident<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, ident: &Ident, ty: Ty<'tcx>) -> bool {
105106
if let ExprKind::Call(body_callee, [body_arg]) = peel_blocks(expr).kind
106-
&& is_res_lang_ctor(cx, path_res(cx, body_callee), OptionSome)
107+
&& is_res_lang_ctor(cx, body_callee.res(cx), OptionSome)
107108
&& cx.typeck_results().expr_ty(body_arg) == ty
108109
&& let ExprKind::Path(QPath::Resolved(
109110
_,
@@ -120,7 +121,7 @@ fn is_some_ident<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, ident: &Ident, t
120121

121122
/// Check if `expr` is `None`, possibly as a block
122123
fn is_none(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
123-
is_res_lang_ctor(cx, path_res(cx, peel_blocks(expr)), OptionNone)
124+
is_res_lang_ctor(cx, peel_blocks(expr).res(cx), OptionNone)
124125
}
125126

126127
/// Suggest replacing `expr` by `scrutinee.METHOD()`, where `METHOD` is either `ok` or

clippy_lints/src/matches/manual_unwrap_or.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::consts::ConstEvalCtxt;
2-
use clippy_utils::res::MaybeDef;
2+
use clippy_utils::res::{MaybeDef, MaybeQPath};
33
use clippy_utils::source::{SpanRangeExt as _, indent_of, reindent_multiline};
44
use rustc_ast::{BindingMode, ByRef};
55
use rustc_errors::Applicability;
@@ -12,7 +12,7 @@ use rustc_span::sym;
1212
use clippy_utils::diagnostics::span_lint_and_sugg;
1313
use clippy_utils::sugg::Sugg;
1414
use clippy_utils::ty::{expr_type_is_certain, implements_trait};
15-
use clippy_utils::{is_default_equivalent, is_lint_allowed, path_res, peel_blocks, span_contains_comment};
15+
use clippy_utils::{is_default_equivalent, is_lint_allowed, peel_blocks, span_contains_comment};
1616

1717
use super::{MANUAL_UNWRAP_OR, MANUAL_UNWRAP_OR_DEFAULT};
1818

@@ -115,7 +115,8 @@ fn handle(
115115
&& is_default_equivalent(cx, peel_blocks(body_none))
116116
{
117117
// We now check if the condition is a None variant, in which case we need to specify the type
118-
if path_res(cx, condition)
118+
if condition
119+
.res(cx)
119120
.opt_def_id()
120121
.is_some_and(|id| Some(cx.tcx.parent(id)) == cx.tcx.lang_items().option_none_variant())
121122
{

0 commit comments

Comments
 (0)