about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/transmute/transmute_int_to_char.rs42
-rw-r--r--clippy_lints/src/transmute/transmute_ptr_to_ref.rs4
-rw-r--r--clippy_lints/src/transmute/transmute_ref_to_ref.rs111
-rw-r--r--clippy_lints/src/use_self.rs2
4 files changed, 77 insertions, 82 deletions
diff --git a/clippy_lints/src/transmute/transmute_int_to_char.rs b/clippy_lints/src/transmute/transmute_int_to_char.rs
index 48473e0d799..29d2450618a 100644
--- a/clippy_lints/src/transmute/transmute_int_to_char.rs
+++ b/clippy_lints/src/transmute/transmute_int_to_char.rs
@@ -17,28 +17,26 @@ pub(super) fn check<'tcx>(
 ) -> bool {
     match (&from_ty.kind(), &to_ty.kind()) {
         (ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => {
-            {
-                span_lint_and_then(
-                    cx,
-                    TRANSMUTE_INT_TO_CHAR,
-                    e.span,
-                    &format!("transmute from a `{}` to a `char`", from_ty),
-                    |diag| {
-                        let arg = sugg::Sugg::hir(cx, &args[0], "..");
-                        let arg = if let ty::Int(_) = from_ty.kind() {
-                            arg.as_ty(ast::UintTy::U32.name_str())
-                        } else {
-                            arg
-                        };
-                        diag.span_suggestion(
-                            e.span,
-                            "consider using",
-                            format!("std::char::from_u32({}).unwrap()", arg.to_string()),
-                            Applicability::Unspecified,
-                        );
-                    },
-                )
-            };
+            span_lint_and_then(
+                cx,
+                TRANSMUTE_INT_TO_CHAR,
+                e.span,
+                &format!("transmute from a `{}` to a `char`", from_ty),
+                |diag| {
+                    let arg = sugg::Sugg::hir(cx, &args[0], "..");
+                    let arg = if let ty::Int(_) = from_ty.kind() {
+                        arg.as_ty(ast::UintTy::U32.name_str())
+                    } else {
+                        arg
+                    };
+                    diag.span_suggestion(
+                        e.span,
+                        "consider using",
+                        format!("std::char::from_u32({}).unwrap()", arg.to_string()),
+                        Applicability::Unspecified,
+                    );
+                },
+            );
             true
         },
         _ => false,
diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs
index a6719b68098..f5dbbbe33bc 100644
--- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs
+++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs
@@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(
     qpath: &'tcx QPath<'_>,
 ) -> bool {
     match (&from_ty.kind(), &to_ty.kind()) {
-        (ty::RawPtr(from_pty), ty::Ref(_, to_ref_ty, mutbl)) => {
+        (ty::RawPtr(from_ptr_ty), ty::Ref(_, to_ref_ty, mutbl)) => {
             span_lint_and_then(
                 cx,
                 TRANSMUTE_PTR_TO_REF,
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
                         ("&*", "*const")
                     };
 
-                    let arg = if from_pty.ty == *to_ref_ty {
+                    let arg = if from_ptr_ty.ty == *to_ref_ty {
                         arg
                     } else {
                         arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))
diff --git a/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/clippy_lints/src/transmute/transmute_ref_to_ref.rs
index ccfcb03e87a..01b00bb0a22 100644
--- a/clippy_lints/src/transmute/transmute_ref_to_ref.rs
+++ b/clippy_lints/src/transmute/transmute_ref_to_ref.rs
@@ -18,70 +18,67 @@ pub(super) fn check<'tcx>(
 ) -> bool {
     let mut triggered = false;
 
-    match (&from_ty.kind(), &to_ty.kind()) {
-        (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => {
-            if_chain! {
-                if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind());
-                if let ty::Uint(ty::UintTy::U8) = slice_ty.kind();
-                if from_mutbl == to_mutbl;
-                then {
-                    let postfix = if *from_mutbl == Mutability::Mut {
-                        "_mut"
-                    } else {
-                        ""
-                    };
+    if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (&from_ty.kind(), &to_ty.kind()) {
+        if_chain! {
+            if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind());
+            if let ty::Uint(ty::UintTy::U8) = slice_ty.kind();
+            if from_mutbl == to_mutbl;
+            then {
+                let postfix = if *from_mutbl == Mutability::Mut {
+                    "_mut"
+                } else {
+                    ""
+                };
 
-                    span_lint_and_sugg(
+                span_lint_and_sugg(
+                    cx,
+                    TRANSMUTE_BYTES_TO_STR,
+                    e.span,
+                    &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
+                    "consider using",
+                    format!(
+                        "std::str::from_utf8{}({}).unwrap()",
+                        postfix,
+                        snippet(cx, args[0].span, ".."),
+                    ),
+                    Applicability::Unspecified,
+                );
+                triggered = true;
+            } else {
+                if (cx.tcx.erase_regions(from_ty) != cx.tcx.erase_regions(to_ty))
+                    && !const_context {
+                    span_lint_and_then(
                         cx,
-                        TRANSMUTE_BYTES_TO_STR,
+                        TRANSMUTE_PTR_TO_PTR,
                         e.span,
-                        &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
-                        "consider using",
-                        format!(
-                            "std::str::from_utf8{}({}).unwrap()",
-                            postfix,
-                            snippet(cx, args[0].span, ".."),
-                        ),
-                        Applicability::Unspecified,
+                        "transmute from a reference to a reference",
+                        |diag| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
+                            let ty_from_and_mut = ty::TypeAndMut {
+                                ty: ty_from,
+                                mutbl: *from_mutbl
+                            };
+                            let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: *to_mutbl };
+                            let sugg_paren = arg
+                                .as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
+                                .as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
+                            let sugg = if *to_mutbl == Mutability::Mut {
+                                sugg_paren.mut_addr_deref()
+                            } else {
+                                sugg_paren.addr_deref()
+                            };
+                            diag.span_suggestion(
+                                e.span,
+                                "try",
+                                sugg.to_string(),
+                                Applicability::Unspecified,
+                            );
+                        },
                     );
-                    triggered = true;
-                } else {
-                    if (cx.tcx.erase_regions(from_ty) != cx.tcx.erase_regions(to_ty))
-                        && !const_context {
-                        span_lint_and_then(
-                            cx,
-                            TRANSMUTE_PTR_TO_PTR,
-                            e.span,
-                            "transmute from a reference to a reference",
-                            |diag| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
-                                let ty_from_and_mut = ty::TypeAndMut {
-                                    ty: ty_from,
-                                    mutbl: *from_mutbl
-                                };
-                                let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: *to_mutbl };
-                                let sugg_paren = arg
-                                    .as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
-                                    .as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
-                                let sugg = if *to_mutbl == Mutability::Mut {
-                                    sugg_paren.mut_addr_deref()
-                                } else {
-                                    sugg_paren.addr_deref()
-                                };
-                                diag.span_suggestion(
-                                    e.span,
-                                    "try",
-                                    sugg.to_string(),
-                                    Applicability::Unspecified,
-                                );
-                            },
-                        );
 
-                        triggered = true;
-                    }
+                    triggered = true;
                 }
             }
-        },
-        _ => {},
+        }
     }
 
     triggered
diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs
index c262ec993b1..f0523cec621 100644
--- a/clippy_lints/src/use_self.rs
+++ b/clippy_lints/src/use_self.rs
@@ -265,7 +265,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
             let hir = cx.tcx.hir();
             let id = hir.get_parent_node(hir_ty.hir_id);
 
-            if !hir.opt_span(id).map(in_macro).unwrap_or(false) {
+            if !hir.opt_span(id).map_or(false, in_macro) {
                 match hir.find(id) {
                     Some(Node::Expr(Expr {
                         kind: ExprKind::Path(QPath::TypeRelative(_, segment)),