@@ -330,6 +330,26 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
330330 let from_ty = cx. typeck_results( ) . expr_ty( & args[ 0 ] ) ;
331331 let to_ty = cx. typeck_results( ) . expr_ty( e) ;
332332
333+ if can_be_expressed_as_pointer_cast( cx, e, from_ty, to_ty) {
334+ span_lint_and_then(
335+ cx,
336+ TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS ,
337+ e. span,
338+ & format!(
339+ "transmute from `{}` to `{}` which could be expressed as a pointer cast instead" ,
340+ from_ty,
341+ to_ty
342+ ) ,
343+ |diag| {
344+ if let Some ( arg) = sugg:: Sugg :: hir_opt( cx, & args[ 0 ] ) {
345+ let sugg = format!( "{} as {}" , arg, to_ty) ;
346+ diag. span_suggestion( e. span, "try" , sugg, Applicability :: Unspecified ) ;
347+ }
348+ }
349+ ) ;
350+ return
351+ }
352+
333353 match ( & from_ty. kind, & to_ty. kind) {
334354 _ if from_ty == to_ty => span_lint(
335355 cx,
@@ -626,25 +646,9 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
626646 ) ;
627647 }
628648 } ,
629- _ => { } ,
630- }
631- if can_be_expressed_as_pointer_cast( cx, e, from_ty, to_ty) {
632- span_lint_and_then(
633- cx,
634- TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS ,
635- e. span,
636- & format!(
637- "transmute from `{}` to `{}` which could be expressed as a pointer cast instead" ,
638- from_ty,
639- to_ty
640- ) ,
641- |diag| {
642- if let Some ( arg) = sugg:: Sugg :: hir_opt( cx, & args[ 0 ] ) {
643- let sugg = format!( "{} as {}" , arg, to_ty) ;
644- diag. span_suggestion( e. span, "try" , sugg, Applicability :: Unspecified ) ;
645- }
646- }
647- )
649+ _ => {
650+ return ;
651+ } ,
648652 }
649653 }
650654 }
0 commit comments