Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cc97592

Browse files
committed
Rename path_to_res to def_path_res
1 parent 8d5d9e0 commit cc97592

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

clippy_lints/src/disallowed_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
7777
fn check_crate(&mut self, cx: &LateContext<'_>) {
7878
for (index, conf) in self.conf_disallowed.iter().enumerate() {
7979
let segs: Vec<_> = conf.path().split("::").collect();
80-
if let Res::Def(_, id) = clippy_utils::path_to_res(cx, &segs) {
80+
if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs) {
8181
self.disallowed.insert(id, index);
8282
}
8383
}

clippy_lints/src/disallowed_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
9696
),
9797
};
9898
let segs: Vec<_> = path.split("::").collect();
99-
match clippy_utils::path_to_res(cx, &segs) {
99+
match clippy_utils::def_path_res(cx, &segs) {
100100
Res::Def(_, id) => {
101101
self.def_ids.insert(id, reason);
102102
},

clippy_lints/src/missing_enforced_import_rename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl_lint_pass!(ImportRename => [MISSING_ENFORCED_IMPORT_RENAMES]);
5858
impl LateLintPass<'_> for ImportRename {
5959
fn check_crate(&mut self, cx: &LateContext<'_>) {
6060
for Rename { path, rename } in &self.conf_renames {
61-
if let Res::Def(_, id) = clippy_utils::path_to_res(cx, &path.split("::").collect::<Vec<_>>()) {
61+
if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &path.split("::").collect::<Vec<_>>()) {
6262
self.renames.insert(id, Symbol::intern(rename));
6363
}
6464
}

clippy_lints/src/utils/internal_lints.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use clippy_utils::macros::root_macro_call_first_node;
44
use clippy_utils::source::snippet;
55
use clippy_utils::ty::match_type;
66
use clippy_utils::{
7-
higher, is_else_clause, is_expn_of, is_expr_path_def_path, is_lint_allowed, match_def_path, method_calls,
8-
path_to_res, paths, peel_blocks_with_stmt, SpanlessEq,
7+
def_path_res, higher, is_else_clause, is_expn_of, is_expr_path_def_path, is_lint_allowed, match_def_path,
8+
method_calls, paths, peel_blocks_with_stmt, SpanlessEq,
99
};
1010
use if_chain::if_chain;
1111
use rustc_ast as ast;
@@ -844,7 +844,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem {
844844
// Extract the path to the matched type
845845
if let Some(segments) = path_to_matched_type(cx, ty_path);
846846
let segments: Vec<&str> = segments.iter().map(Symbol::as_str).collect();
847-
if let Some(ty_did) = path_to_res(cx, &segments[..]).opt_def_id();
847+
if let Some(ty_did) = def_path_res(cx, &segments[..]).opt_def_id();
848848
// Check if the matched type is a diagnostic item
849849
if let Some(item_name) = cx.tcx.get_diagnostic_name(ty_did);
850850
then {
@@ -917,7 +917,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Ve
917917
// This is not a complete resolver for paths. It works on all the paths currently used in the paths
918918
// module. That's all it does and all it needs to do.
919919
pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
920-
if path_to_res(cx, path) != Res::Err {
920+
if def_path_res(cx, path) != Res::Err {
921921
return true;
922922
}
923923

@@ -999,7 +999,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
999999
}
10001000

10011001
for &module in &[&paths::KW_MODULE, &paths::SYM_MODULE] {
1002-
if let Some(def_id) = path_to_res(cx, module).opt_def_id() {
1002+
if let Some(def_id) = def_path_res(cx, module).opt_def_id() {
10031003
for item in cx.tcx.module_children(def_id).iter() {
10041004
if_chain! {
10051005
if let Res::Def(DefKind::Const, item_def_id) = item.res;

clippy_utils/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ pub fn path_to_local_id(expr: &Expr<'_>, id: HirId) -> bool {
497497
path_to_local(expr) == Some(id)
498498
}
499499

500-
/// Gets the definition associated to a path.
501-
pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
500+
/// Resolves a def path like `std::vec::Vec`.
501+
/// This function is expensive and should be used sparingly.
502+
pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
502503
macro_rules! try_res {
503504
($e:expr) => {
504505
match $e {
@@ -574,7 +575,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
574575
/// Convenience function to get the `DefId` of a trait by path.
575576
/// It could be a trait or trait alias.
576577
pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option<DefId> {
577-
match path_to_res(cx, path) {
578+
match def_path_res(cx, path) {
578579
Res::Def(DefKind::Trait | DefKind::TraitAlias, trait_id) => Some(trait_id),
579580
_ => None,
580581
}

0 commit comments

Comments
 (0)