@@ -62,11 +62,10 @@ impl<'a, 'tcx> RedundantTransmutesChecker<'a, 'tcx> {
6262 span,
6363 } ) ;
6464 }
65- return match input. kind ( ) {
65+ match input. kind ( ) {
6666 // char → u32
67- Char => matches ! ( fn_sig. output( ) . kind( ) , Uint ( UintTy :: U32 ) ) . then ( || {
68- errors:: RedundantTransmute { sugg : format ! ( "({arg}) as u32" ) , help : None , span }
69- } ) ,
67+ Char => matches ! ( fn_sig. output( ) . kind( ) , Uint ( UintTy :: U32 ) )
68+ . then ( || errors:: RedundantTransmute :: new ( format ! ( "({arg}) as u32" ) , span) ) ,
7069 // u32 → char
7170 Uint ( UintTy :: U32 ) if * fn_sig. output ( ) . kind ( ) == Char => {
7271 Some ( errors:: RedundantTransmute {
@@ -75,19 +74,26 @@ impl<'a, 'tcx> RedundantTransmutesChecker<'a, 'tcx> {
7574 span,
7675 } )
7776 }
78- // bool → (uNN ↔ iNN)
79- Bool | Uint ( ..) | Int ( ..) => {
80- matches ! ( fn_sig. output( ) . kind( ) , Int ( ..) | Uint ( ..) ) . then ( || {
81- // FIXME: suggest `cast_unsigned`/ `cast_signed` when `integer_sign_cast` stabilizes
82- errors:: RedundantTransmute {
83- sugg : format ! ( "({arg}) as {}" , fn_sig. output( ) ) ,
84- help : None ,
85- span,
86- }
87- } )
77+ // uNN → iNN
78+ Uint ( ty) if matches ! ( fn_sig. output( ) . kind( ) , Int ( ..) ) => {
79+ Some ( errors:: RedundantTransmute :: new (
80+ format ! ( "{}::cast_signed({arg})" , ty. name_str( ) ) ,
81+ span,
82+ ) )
8883 }
84+ // iNN → uNN
85+ Int ( ty) if matches ! ( fn_sig. output( ) . kind( ) , Uint ( ..) ) => {
86+ Some ( errors:: RedundantTransmute :: new (
87+ format ! ( "{}::cast_unsigned({arg})" , ty. name_str( ) ) ,
88+ span,
89+ ) )
90+ }
91+ // bool → { uNN, iNN }
92+ Bool if matches ! ( fn_sig. output( ) . kind( ) , Int ( ..) | Uint ( ..) ) => Some (
93+ errors:: RedundantTransmute :: new ( format ! ( "({arg}) as {}" , fn_sig. output( ) ) , span) ,
94+ ) ,
8995 _ => None ,
90- } ;
96+ }
9197 }
9298}
9399
0 commit comments