Skip to content

Commit 79982a2

Browse files
committed
Make use of some existing diagnostic items
1 parent 1d1b6d8 commit 79982a2

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

clippy_lints/src/mem_replace.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::lint::in_external_macro;
1010
use rustc_session::{declare_lint_pass, declare_tool_lint};
1111
use rustc_span::source_map::Span;
12+
use rustc_span::symbol::sym;
1213

1314
declare_clippy_lint! {
1415
/// **What it does:** Checks for `mem::replace()` on an `Option` with
@@ -141,15 +142,15 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span
141142
if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind;
142143
if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
143144
then {
144-
if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) {
145+
if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) {
145146
span_lint_and_help(
146147
cx,
147148
MEM_REPLACE_WITH_UNINIT,
148149
expr_span,
149150
"replacing with `mem::uninitialized()`",
150151
"consider using the `take_mut` crate instead",
151152
);
152-
} else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) &&
153+
} else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) &&
153154
!cx.tables.expr_ty(src).is_primitive() {
154155
span_lint_and_help(
155156
cx,

clippy_lints/src/methods/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1998,9 +1998,9 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &h
19981998
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(arg));
19991999

20002000
if let ty::Adt(_, subst) = obj_ty.kind {
2001-
let caller_type = if match_type(cx, obj_ty, &paths::RC) {
2001+
let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) {
20022002
"Rc"
2003-
} else if match_type(cx, obj_ty, &paths::ARC) {
2003+
} else if is_type_diagnostic_item(cx, obj_ty, sym::Arc) {
20042004
"Arc"
20052005
} else if match_type(cx, obj_ty, &paths::WEAK_RC) || match_type(cx, obj_ty, &paths::WEAK_ARC) {
20062006
"Weak"

clippy_lints/src/utils/paths.rs

-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! See <https://github.com/rust-lang/rust-clippy/issues/5393> for more information.
66
77
pub const ANY_TRAIT: [&str; 3] = ["std", "any", "Any"];
8-
pub const ARC: [&str; 3] = ["alloc", "sync", "Arc"];
98
pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
109
pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
1110
pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
@@ -62,8 +61,6 @@ pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
6261
pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"];
6362
pub const MEM_MAYBEUNINIT_UNINIT: [&str; 5] = ["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"];
6463
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];
65-
pub const MEM_UNINITIALIZED: [&str; 3] = ["core", "mem", "uninitialized"];
66-
pub const MEM_ZEROED: [&str; 3] = ["core", "mem", "zeroed"];
6764
pub const MUTEX: [&str; 4] = ["std", "sync", "mutex", "Mutex"];
6865
pub const MUTEX_GUARD: [&str; 4] = ["std", "sync", "mutex", "MutexGuard"];
6966
pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"];

0 commit comments

Comments
 (0)