]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/trivially_copy_pass_by_ref.rs
MutImmutable -> Immutable, MutMutable -> Mutable, CaptureClause -> CaptureBy
[rust.git] / clippy_lints / src / trivially_copy_pass_by_ref.rs
index be79fc2fb81fb20852f92560659a80c1829656ca..616568f36eebe1fc0f28a62a17025d60b99b6026 100644 (file)
@@ -1,6 +1,6 @@
 use std::cmp;
 
-use crate::utils::{in_macro_or_desugar, is_copy, is_self_ty, snippet, span_lint_and_sugg};
+use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
 use if_chain::if_chain;
 use matches::matches;
 use rustc::hir;
@@ -54,6 +54,7 @@
     "functions taking small copyable arguments by reference"
 }
 
+#[derive(Copy, Clone)]
 pub struct TriviallyCopyPassByRef {
     limit: u64,
 }
@@ -82,7 +83,7 @@ fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &Fn
         // Use lifetimes to determine if we're returning a reference to the
         // argument. In that case we can't switch to pass-by-value as the
         // argument will not live long enough.
-        let output_lts = match fn_sig.output().sty {
+        let output_lts = match fn_sig.output().kind {
             ty::Ref(output_lt, _, _) => vec![output_lt],
             ty::Adt(_, substs) => substs.regions().collect(),
             _ => vec![],
@@ -96,12 +97,12 @@ fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &Fn
             }
 
             if_chain! {
-                if let ty::Ref(input_lt, ty, Mutability::MutImmutable) = ty.sty;
+                if let ty::Ref(input_lt, ty, Mutability::Immutable) = ty.kind;
                 if !output_lts.contains(&input_lt);
                 if is_copy(cx, ty);
                 if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());
                 if size <= self.limit;
-                if let hir::TyKind::Rptr(_, MutTy { ty: ref decl_ty, .. }) = input.node;
+                if let hir::TyKind::Rptr(_, MutTy { ty: ref decl_ty, .. }) = input.kind;
                 then {
                     let value_type = if is_self_ty(decl_ty) {
                         "self".into()
@@ -127,11 +128,11 @@ fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &Fn
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
     fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
-        if in_macro_or_desugar(item.span) {
+        if item.span.from_expansion() {
             return;
         }
 
-        if let hir::TraitItemKind::Method(method_sig, _) = &item.node {
+        if let hir::TraitItemKind::Method(method_sig, _) = &item.kind {
             self.check_poly_fn(cx, item.hir_id, &*method_sig.decl, None);
         }
     }
@@ -145,7 +146,7 @@ fn check_fn(
         span: Span,
         hir_id: HirId,
     ) {
-        if in_macro_or_desugar(span) {
+        if span.from_expansion() {
             return;
         }
 
@@ -166,7 +167,7 @@ fn check_fn(
 
         // Exclude non-inherent impls
         if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
-            if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
+            if matches!(item.kind, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
                 ItemKind::Trait(..))
             {
                 return;