mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
[Clippy] Swap redundant_clone
to use diagnostic items instead of paths
This commit is contained in:
parent
c891082029
commit
afe7907914
@ -1370,6 +1370,7 @@ symbols! {
|
|||||||
or,
|
or,
|
||||||
or_patterns,
|
or_patterns,
|
||||||
ord_cmp_method,
|
ord_cmp_method,
|
||||||
|
os_str_to_os_string,
|
||||||
os_string_as_os_str,
|
os_string_as_os_str,
|
||||||
other,
|
other,
|
||||||
out,
|
out,
|
||||||
@ -1424,6 +1425,7 @@ symbols! {
|
|||||||
pat_param,
|
pat_param,
|
||||||
patchable_function_entry,
|
patchable_function_entry,
|
||||||
path,
|
path,
|
||||||
|
path_to_pathbuf,
|
||||||
pathbuf_as_path,
|
pathbuf_as_path,
|
||||||
pattern_complexity,
|
pattern_complexity,
|
||||||
pattern_parentheses,
|
pattern_parentheses,
|
||||||
|
@ -919,6 +919,7 @@ impl OsStr {
|
|||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "os_str_to_os_string")]
|
||||||
pub fn to_os_string(&self) -> OsString {
|
pub fn to_os_string(&self) -> OsString {
|
||||||
OsString { inner: self.inner.to_owned() }
|
OsString { inner: self.inner.to_owned() }
|
||||||
}
|
}
|
||||||
|
@ -2265,6 +2265,7 @@ impl Path {
|
|||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "path_to_pathbuf")]
|
||||||
pub fn to_path_buf(&self) -> PathBuf {
|
pub fn to_path_buf(&self) -> PathBuf {
|
||||||
PathBuf::from(self.inner.to_os_string())
|
PathBuf::from(self.inner.to_os_string())
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
|
|||||||
use clippy_utils::mir::{visit_local_usage, LocalUsage, PossibleBorrowerMap};
|
use clippy_utils::mir::{visit_local_usage, LocalUsage, PossibleBorrowerMap};
|
||||||
use clippy_utils::source::SpanRangeExt;
|
use clippy_utils::source::SpanRangeExt;
|
||||||
use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, is_type_lang_item, walk_ptrs_ty_depth};
|
use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, is_type_lang_item, walk_ptrs_ty_depth};
|
||||||
use clippy_utils::{fn_has_unsatisfiable_preds, match_def_path, paths};
|
use clippy_utils::fn_has_unsatisfiable_preds;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{def_id, Body, FnDecl, LangItem};
|
use rustc_hir::{def_id, Body, FnDecl, LangItem};
|
||||||
@ -102,8 +102,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
|
|||||||
&& is_type_lang_item(cx, arg_ty, LangItem::String));
|
&& is_type_lang_item(cx, arg_ty, LangItem::String));
|
||||||
|
|
||||||
let from_deref = !from_borrow
|
let from_deref = !from_borrow
|
||||||
&& (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF)
|
&& (cx.tcx.is_diagnostic_item(sym::path_to_pathbuf, fn_def_id)
|
||||||
|| match_def_path(cx, fn_def_id, &paths::OS_STR_TO_OS_STRING));
|
|| cx.tcx.is_diagnostic_item(sym::os_str_to_os_string, fn_def_id));
|
||||||
|
|
||||||
if !from_borrow && !from_deref {
|
if !from_borrow && !from_deref {
|
||||||
continue;
|
continue;
|
||||||
|
@ -37,12 +37,10 @@ pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"];
|
|||||||
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
|
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
|
||||||
pub const MSRV: [&str; 3] = ["clippy_config", "msrvs", "Msrv"];
|
pub const MSRV: [&str; 3] = ["clippy_config", "msrvs", "Msrv"];
|
||||||
pub const OPEN_OPTIONS_NEW: [&str; 4] = ["std", "fs", "OpenOptions", "new"];
|
pub const OPEN_OPTIONS_NEW: [&str; 4] = ["std", "fs", "OpenOptions", "new"];
|
||||||
pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"];
|
|
||||||
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
|
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
|
||||||
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockReadGuard"];
|
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockReadGuard"];
|
||||||
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
|
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
|
||||||
pub const PATH_MAIN_SEPARATOR: [&str; 3] = ["std", "path", "MAIN_SEPARATOR"];
|
pub const PATH_MAIN_SEPARATOR: [&str; 3] = ["std", "path", "MAIN_SEPARATOR"];
|
||||||
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
|
|
||||||
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
|
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
|
||||||
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
|
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
|
||||||
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
|
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
|
||||||
|
Loading…
Reference in New Issue
Block a user