]> git.lizzy.rs Git - rust.git/commitdiff
Make use of some existing diagnostic items
authorPhilipp Hansch <dev@phansch.net>
Fri, 10 Apr 2020 21:18:03 +0000 (23:18 +0200)
committerPhilipp Hansch <dev@phansch.net>
Sun, 12 Apr 2020 11:58:04 +0000 (13:58 +0200)
clippy_lints/src/mem_replace.rs
clippy_lints/src/methods/mod.rs
clippy_lints/src/utils/paths.rs

index 35b8842dc450b64027600665ab5d55ec29088c11..0bd4c4805b34c3d2f4d285a0963d136a720271c0 100644 (file)
@@ -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,
index 19ed50c42e35cad5140af9a0d47c811002f3971b..850633791e1610ea906c086f5e4ce0d5e322c9cf 100644 (file)
@@ -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"
index 7a6a6b02ed031a8346797bfdaf29cb9c9a16ee6b..d93f8a1e5609c47379daac3b54a2cb3c6476124d 100644 (file)
@@ -5,7 +5,6 @@
 //! See <https://github.com/rust-lang/rust-clippy/issues/5393> 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"];