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

Commit 7ffd485

Browse files
committed
[Clippy] Swap option_as_ref_deref to use diagnostic items instead of paths
1 parent 71dbfd5 commit 7ffd485

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

clippy_lints/src/methods/option_as_ref_deref.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use clippy_config::msrvs::{self, Msrv};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::snippet;
44
use clippy_utils::ty::is_type_diagnostic_item;
5-
use clippy_utils::{match_def_path, path_to_local_id, paths, peel_blocks};
5+
use clippy_utils::{path_to_local_id, peel_blocks};
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
88
use rustc_lint::LateContext;
99
use rustc_middle::ty;
10-
use rustc_span::sym;
10+
use rustc_span::{sym, Symbol};
1111

1212
use super::OPTION_AS_REF_DEREF;
1313

@@ -31,14 +31,14 @@ pub(super) fn check(
3131
return;
3232
}
3333

34-
let deref_aliases: [&[&str]; 7] = [
35-
&paths::CSTRING_AS_C_STR,
36-
&paths::OS_STRING_AS_OS_STR,
37-
&paths::PATH_BUF_AS_PATH,
38-
&paths::STRING_AS_STR,
39-
&paths::STRING_AS_MUT_STR,
40-
&paths::VEC_AS_SLICE,
41-
&paths::VEC_AS_MUT_SLICE,
34+
let deref_aliases: [Symbol; 7] = [
35+
sym::cstring_as_c_str,
36+
sym::os_string_as_os_str,
37+
sym::pathbuf_as_path,
38+
sym::string_as_str,
39+
sym::string_as_mut_str,
40+
sym::vec_as_slice,
41+
sym::vec_as_mut_slice,
4242
];
4343

4444
let is_deref = match map_arg.kind {
@@ -48,7 +48,7 @@ pub(super) fn check(
4848
.map_or(false, |fun_def_id| {
4949
cx.tcx.is_diagnostic_item(sym::deref_method, fun_def_id)
5050
|| cx.tcx.is_diagnostic_item(sym::deref_mut_method, fun_def_id)
51-
|| deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
51+
|| deref_aliases.iter().any(|&sym| cx.tcx.is_diagnostic_item(sym, fun_def_id))
5252
})
5353
},
5454
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
@@ -69,7 +69,7 @@ pub(super) fn check(
6969
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
7070
cx.tcx.is_diagnostic_item(sym::deref_method, method_did)
7171
|| cx.tcx.is_diagnostic_item(sym::deref_mut_method, method_did)
72-
|| deref_aliases.iter().any(|path| match_def_path(cx, method_did, path))
72+
|| deref_aliases.iter().any(|&sym| cx.tcx.is_diagnostic_item(sym, method_did))
7373
} else {
7474
false
7575
}

clippy_utils/src/paths.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
1212
["rustc_lint_defs", "Applicability", "MachineApplicable"],
1313
];
1414
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
15-
pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"];
1615
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
1716
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];
1817
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
@@ -40,12 +39,10 @@ pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"];
4039
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
4140
pub const MSRV: [&str; 3] = ["clippy_config", "msrvs", "Msrv"];
4241
pub const OPEN_OPTIONS_NEW: [&str; 4] = ["std", "fs", "OpenOptions", "new"];
43-
pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"];
4442
pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"];
4543
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
4644
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockReadGuard"];
4745
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
48-
pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"];
4946
pub const PATH_MAIN_SEPARATOR: [&str; 3] = ["std", "path", "MAIN_SEPARATOR"];
5047
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
5148
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
@@ -62,8 +59,6 @@ pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
6259
pub const SLICE_INTO_VEC: [&str; 4] = ["alloc", "slice", "<impl [T]>", "into_vec"];
6360
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
6461
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
65-
pub const STRING_AS_MUT_STR: [&str; 4] = ["alloc", "string", "String", "as_mut_str"];
66-
pub const STRING_AS_STR: [&str; 4] = ["alloc", "string", "String", "as_str"];
6762
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
6863
pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];
6964
pub const STR_LEN: [&str; 4] = ["core", "str", "<impl str>", "len"];
@@ -85,8 +80,6 @@ pub const TOKIO_IO_ASYNCWRITEEXT: [&str; 5] = ["tokio", "io", "util", "async_wri
8580
pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "OpenOptions"];
8681
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
8782
pub const TOKIO_IO_OPEN_OPTIONS_NEW: [&str; 5] = ["tokio", "fs", "open_options", "OpenOptions", "new"];
88-
pub const VEC_AS_MUT_SLICE: [&str; 4] = ["alloc", "vec", "Vec", "as_mut_slice"];
89-
pub const VEC_AS_SLICE: [&str; 4] = ["alloc", "vec", "Vec", "as_slice"];
9083
pub const VEC_FROM_ELEM: [&str; 3] = ["alloc", "vec", "from_elem"];
9184
pub const VEC_NEW: [&str; 4] = ["alloc", "vec", "Vec", "new"];
9285
pub const VEC_WITH_CAPACITY: [&str; 4] = ["alloc", "vec", "Vec", "with_capacity"];

0 commit comments

Comments
 (0)