about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRyan1729 <Ryan1729@gmail.com>2020-08-03 00:16:11 -0600
committerRyan1729 <Ryan1729@gmail.com>2020-08-06 04:24:24 -0600
commitb4ecee9edeca0f234c2074b929f5333bee4e76a5 (patch)
treeb7a898b2165eaa9bc7fe021338f8d6845c445694
parent7061b1c0933efc2321d9e30413a746610c8e5e8c (diff)
downloadrust-b4ecee9edeca0f234c2074b929f5333bee4e76a5.tar.gz
rust-b4ecee9edeca0f234c2074b929f5333bee4e76a5.zip
accidentally cause an ICE by putting the TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS handling after the match
The reason I did this in the first place was to try and figure out why I don't see my expected 7 error messages
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute.rs34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/tools/clippy/clippy_lints/src/transmute.rs b/src/tools/clippy/clippy_lints/src/transmute.rs
index d5b694ce311..d6b1a5df71f 100644
--- a/src/tools/clippy/clippy_lints/src/transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute.rs
@@ -626,21 +626,25 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
                             );
                         }
                     },
-                    (_, _) if can_be_expressed_as_pointer_cast(cx, e, from_ty, to_ty) => {
-                        span_lint(
-                            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
-                            )
-                        );
-                    },
-                    _ => {
-                        return
-                    },
+                    _ => {},
+                }
+                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);
+                            }
+                        }
+                    )
                 }
             }
         }