]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/ptr.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / ptr.rs
index 8a6933b2f5a4f652fb2e4b5dcb712d5b8121022b..d95d61e4027eb2eb64f955a429eae46c6bf30026 100644 (file)
@@ -1,8 +1,10 @@
 //! Checks for usage of  `&Vec[_]` and `&String`.
 
 use crate::utils::ptr::get_spans;
-use crate::utils::sym;
-use crate::utils::{match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_then, walk_ptrs_hir_ty};
+use crate::utils::{
+    is_type_diagnostic_item, match_qpath, match_type, paths, snippet_opt, span_lint, span_lint_and_then,
+    walk_ptrs_hir_ty,
+};
 use if_chain::if_chain;
 use rustc::hir::QPath;
 use rustc::hir::*;
@@ -12,7 +14,7 @@
 use rustc_errors::Applicability;
 use std::borrow::Cow;
 use syntax::source_map::Span;
-use syntax_pos::MultiSpan;
+use syntax_pos::{MultiSpan, Symbol};
 
 declare_clippy_lint! {
     /// **What it does:** This lint checks for function arguments of type `&String`
@@ -107,7 +109,7 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
     fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
         if let ImplItemKind::Method(ref sig, body_id) = item.node {
             let parent_item = cx.tcx.hir().get_parent_item(item.hir_id);
-            if let Some(Node::Item(it)) = cx.tcx.hir().find_by_hir_id(parent_item) {
+            if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) {
                 if let ItemKind::Impl(_, _, _, _, Some(_), _, _) = it.node {
                     return; // ignore trait impls
                 }
@@ -143,13 +145,13 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
 
 #[allow(clippy::too_many_lines)]
 fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) {
-    let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_id);
+    let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
     let sig = cx.tcx.fn_sig(fn_def_id);
     let fn_ty = sig.skip_binder();
 
     for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
         if let ty::Ref(_, ty, MutImmutable) = ty.sty {
-            if match_type(cx, ty, &*paths::VEC) {
+            if is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) {
                 let mut ty_snippet = None;
                 if_chain! {
                     if let TyKind::Path(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).node;
@@ -164,7 +166,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
                         }
                     }
                 };
-                if let Some(spans) = get_spans(cx, opt_body_id, idx, &[(*sym::clone, ".to_owned()")]) {
+                if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_owned()")]) {
                     span_lint_and_then(
                         cx,
                         PTR_ARG,
@@ -193,13 +195,8 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
                         },
                     );
                 }
-            } else if match_type(cx, ty, &*paths::STRING) {
-                if let Some(spans) = get_spans(
-                    cx,
-                    opt_body_id,
-                    idx,
-                    &[(*sym::clone, ".to_string()"), (*sym::as_str, "")],
-                ) {
+            } else if match_type(cx, ty, &paths::STRING) {
+                if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) {
                     span_lint_and_then(
                         cx,
                         PTR_ARG,
@@ -220,7 +217,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
                         },
                     );
                 }
-            } else if match_type(cx, ty, &*paths::COW) {
+            } else if match_type(cx, ty, &paths::COW) {
                 if_chain! {
                     if let TyKind::Rptr(_, MutTy { ref ty, ..} ) = arg.node;
                     if let TyKind::Path(ref path) = ty.node;
@@ -299,7 +296,7 @@ fn is_null_path(expr: &Expr) -> bool {
     if let ExprKind::Call(ref pathexp, ref args) = expr.node {
         if args.is_empty() {
             if let ExprKind::Path(ref path) = pathexp.node {
-                return match_qpath(path, &*paths::PTR_NULL) || match_qpath(path, &*paths::PTR_NULL_MUT);
+                return match_qpath(path, &paths::PTR_NULL) || match_qpath(path, &paths::PTR_NULL_MUT);
             }
         }
     }