about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRyan1729 <Ryan1729@gmail.com>2020-08-03 00:54:03 -0600
committerRyan1729 <Ryan1729@gmail.com>2020-08-06 04:24:24 -0600
commit1e5c14df58ddbaf203eb2b6a3d89edd6080f3dd7 (patch)
tree9853df9cecd6b48c09d6189bd9cbd0b15d786dc3
parentb4ecee9edeca0f234c2074b929f5333bee4e76a5 (diff)
downloadrust-1e5c14df58ddbaf203eb2b6a3d89edd6080f3dd7.tar.gz
rust-1e5c14df58ddbaf203eb2b6a3d89edd6080f3dd7.zip
try putting the can_be_expressed_as_pointer_cast at the top and find that we still get an ICE
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute.rs42
-rw-r--r--src/tools/clippy/tests/ui/transmute.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs2
3 files changed, 25 insertions, 21 deletions
diff --git a/src/tools/clippy/clippy_lints/src/transmute.rs b/src/tools/clippy/clippy_lints/src/transmute.rs
index d6b1a5df71f..7ab3f0d9676 100644
--- a/src/tools/clippy/clippy_lints/src/transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute.rs
@@ -330,6 +330,26 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
                 let from_ty = cx.typeck_results().expr_ty(&args[0]);
                 let to_ty = cx.typeck_results().expr_ty(e);
 
+                if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
+                    span_lint_and_then(
+                        cx,
+                        TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
+                        e.span,
+                        &format!(
+                            "transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
+                            from_ty,
+                            to_ty
+                        ),
+                        |diag| {
+                            if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
+                                let sugg = format!("{} as {}", arg, to_ty);
+                                diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
+                            }
+                        }
+                    );
+                    return
+                }
+
                 match (&from_ty.kind, &to_ty.kind) {
                     _ if from_ty == to_ty => span_lint(
                         cx,
@@ -626,25 +646,9 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
                             );
                         }
                     },
-                    _ => {},
-                }
-                if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) {
-                    span_lint_and_then(
-                        cx,
-                        TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
-                        e.span,
-                        &format!(
-                            "transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
-                            from_ty,
-                            to_ty
-                        ),
-                        |diag| {
-                            if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
-                                let sugg = format!("{} as {}", arg, to_ty);
-                                diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
-                            }
-                        }
-                    )
+                    _ => {
+                        return;
+                    },
                 }
             }
         }
diff --git a/src/tools/clippy/tests/ui/transmute.rs b/src/tools/clippy/tests/ui/transmute.rs
index bb853d23704..b3171d2e7dc 100644
--- a/src/tools/clippy/tests/ui/transmute.rs
+++ b/src/tools/clippy/tests/ui/transmute.rs
@@ -1,7 +1,7 @@
 #![allow(dead_code)]
+#![allow(clippy::transmutes_expressible_as_ptr_casts)]
 
 extern crate core;
-
 use std::mem::transmute as my_transmute;
 use std::vec::Vec as MyVec;
 
diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs
index 0d8a322f2b2..009b5fa534c 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs
@@ -1,5 +1,5 @@
 #![warn(clippy::transmute_ptr_to_ptr)]
-
+#![allow(clippy::transmutes_expressible_as_ptr_casts)]
 // Make sure we can modify lifetimes, which is one of the recommended uses
 // of transmute