From: Philipp Hansch Date: Fri, 10 Apr 2020 21:18:03 +0000 (+0200) Subject: Make use of some existing diagnostic items X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=79982a2813c88e1426b17376b2a4b2bec352ee59;p=rust.git Make use of some existing diagnostic items --- diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 35b8842dc45..0bd4c4805b3 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -9,6 +9,7 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; +use rustc_span::symbol::sym; declare_clippy_lint! { /// **What it does:** Checks for `mem::replace()` on an `Option` with @@ -141,7 +142,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); then { - if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) { + if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) { span_lint_and_help( cx, MEM_REPLACE_WITH_UNINIT, @@ -149,7 +150,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span "replacing with `mem::uninitialized()`", "consider using the `take_mut` crate instead", ); - } else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) && + } else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) && !cx.tables.expr_ty(src).is_primitive() { span_lint_and_help( cx, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 19ed50c42e3..850633791e1 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1998,9 +1998,9 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &h let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(arg)); if let ty::Adt(_, subst) = obj_ty.kind { - let caller_type = if match_type(cx, obj_ty, &paths::RC) { + let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { "Rc" - } else if match_type(cx, obj_ty, &paths::ARC) { + } else if is_type_diagnostic_item(cx, obj_ty, sym::Arc) { "Arc" } else if match_type(cx, obj_ty, &paths::WEAK_RC) || match_type(cx, obj_ty, &paths::WEAK_ARC) { "Weak" diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 7a6a6b02ed0..d93f8a1e560 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -5,7 +5,6 @@ //! See for more information. pub const ANY_TRAIT: [&str; 3] = ["std", "any", "Any"]; -pub const ARC: [&str; 3] = ["alloc", "sync", "Arc"]; pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"]; pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"]; pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"]; @@ -62,8 +61,6 @@ pub const MEM_MAYBEUNINIT: [&str; 4] = ["core", "mem", "maybe_uninit", "MaybeUninit"]; pub const MEM_MAYBEUNINIT_UNINIT: [&str; 5] = ["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]; pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"]; -pub const MEM_UNINITIALIZED: [&str; 3] = ["core", "mem", "uninitialized"]; -pub const MEM_ZEROED: [&str; 3] = ["core", "mem", "zeroed"]; pub const MUTEX: [&str; 4] = ["std", "sync", "mutex", "Mutex"]; pub const MUTEX_GUARD: [&str; 4] = ["std", "sync", "mutex", "MutexGuard"]; pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"];