Skip to content

Commit afe7907

Browse files
committed
[Clippy] Swap redundant_clone to use diagnostic items instead of paths
1 parent c891082 commit afe7907

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ symbols! {
13701370
or,
13711371
or_patterns,
13721372
ord_cmp_method,
1373+
os_str_to_os_string,
13731374
os_string_as_os_str,
13741375
other,
13751376
out,
@@ -1424,6 +1425,7 @@ symbols! {
14241425
pat_param,
14251426
patchable_function_entry,
14261427
path,
1428+
path_to_pathbuf,
14271429
pathbuf_as_path,
14281430
pattern_complexity,
14291431
pattern_parentheses,

library/std/src/ffi/os_str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ impl OsStr {
919919
#[must_use = "this returns the result of the operation, \
920920
without modifying the original"]
921921
#[inline]
922+
#[cfg_attr(not(test), rustc_diagnostic_item = "os_str_to_os_string")]
922923
pub fn to_os_string(&self) -> OsString {
923924
OsString { inner: self.inner.to_owned() }
924925
}

library/std/src/path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,7 @@ impl Path {
22652265
#[must_use = "this returns the result of the operation, \
22662266
without modifying the original"]
22672267
#[stable(feature = "rust1", since = "1.0.0")]
2268+
#[cfg_attr(not(test), rustc_diagnostic_item = "path_to_pathbuf")]
22682269
pub fn to_path_buf(&self) -> PathBuf {
22692270
PathBuf::from(self.inner.to_os_string())
22702271
}

src/tools/clippy/clippy_lints/src/redundant_clone.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
22
use clippy_utils::mir::{visit_local_usage, LocalUsage, PossibleBorrowerMap};
33
use clippy_utils::source::SpanRangeExt;
44
use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, is_type_lang_item, walk_ptrs_ty_depth};
5-
use clippy_utils::{fn_has_unsatisfiable_preds, match_def_path, paths};
5+
use clippy_utils::fn_has_unsatisfiable_preds;
66
use rustc_errors::Applicability;
77
use rustc_hir::intravisit::FnKind;
88
use rustc_hir::{def_id, Body, FnDecl, LangItem};
@@ -102,8 +102,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
102102
&& is_type_lang_item(cx, arg_ty, LangItem::String));
103103

104104
let from_deref = !from_borrow
105-
&& (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF)
106-
|| match_def_path(cx, fn_def_id, &paths::OS_STR_TO_OS_STRING));
105+
&& (cx.tcx.is_diagnostic_item(sym::path_to_pathbuf, fn_def_id)
106+
|| cx.tcx.is_diagnostic_item(sym::os_str_to_os_string, fn_def_id));
107107

108108
if !from_borrow && !from_deref {
109109
continue;

src/tools/clippy/clippy_utils/src/paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"];
3737
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
3838
pub const MSRV: [&str; 3] = ["clippy_config", "msrvs", "Msrv"];
3939
pub const OPEN_OPTIONS_NEW: [&str; 4] = ["std", "fs", "OpenOptions", "new"];
40-
pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"];
4140
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
4241
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockReadGuard"];
4342
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
4443
pub const PATH_MAIN_SEPARATOR: [&str; 3] = ["std", "path", "MAIN_SEPARATOR"];
45-
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
4644
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
4745
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
4846
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];

0 commit comments

Comments
 (0)