@@ -91,15 +91,14 @@ pub(super) fn check(
9191 cast_to : Ty < ' _ > ,
9292 cast_to_span : Span ,
9393) {
94- let msg = match ( cast_from. kind ( ) , cast_to . is_integral ( ) ) {
95- ( ty:: Int ( _) | ty:: Uint ( _) , true ) => {
94+ let msg = match ( cast_from. kind ( ) , utils :: int_ty_to_nbits ( cx . tcx , cast_to ) ) {
95+ ( ty:: Int ( _) | ty:: Uint ( _) , Some ( to_nbits ) ) => {
9696 let from_nbits = apply_reductions (
9797 cx,
98- utils:: int_ty_to_nbits ( cast_from , cx. tcx ) ,
98+ utils:: int_ty_to_nbits ( cx. tcx , cast_from ) . unwrap ( ) ,
9999 cast_expr,
100100 cast_from. is_signed ( ) ,
101101 ) ;
102- let to_nbits = utils:: int_ty_to_nbits ( cast_to, cx. tcx ) ;
103102
104103 let ( should_lint, suffix) = match ( is_isize_or_usize ( cast_from) , is_isize_or_usize ( cast_to) ) {
105104 ( true , true ) | ( false , false ) => ( to_nbits < from_nbits, "" ) ,
@@ -121,7 +120,7 @@ pub(super) fn check(
121120 format ! ( "casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}" , )
122121 } ,
123122
124- ( ty:: Adt ( def, _) , true ) if def. is_enum ( ) => {
123+ ( ty:: Adt ( def, _) , Some ( to_nbits ) ) if def. is_enum ( ) => {
125124 let ( from_nbits, variant) = if let ExprKind :: Path ( p) = & cast_expr. kind
126125 && let Res :: Def ( DefKind :: Ctor ( ..) , id) = cx. qpath_res ( p, cast_expr. hir_id )
127126 {
@@ -132,7 +131,6 @@ pub(super) fn check(
132131 } else {
133132 ( utils:: enum_ty_to_nbits ( * def, cx. tcx ) , None )
134133 } ;
135- let to_nbits = utils:: int_ty_to_nbits ( cast_to, cx. tcx ) ;
136134
137135 let cast_from_ptr_size = def. repr ( ) . int . is_none_or ( |ty| matches ! ( ty, IntegerType :: Pointer ( _) , ) ) ;
138136 let suffix = match ( cast_from_ptr_size, is_isize_or_usize ( cast_to) ) {
@@ -157,11 +155,11 @@ pub(super) fn check(
157155 format ! ( "casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}" )
158156 } ,
159157
160- ( ty:: Float ( _) , true ) => {
158+ ( ty:: Float ( _) , Some ( _ ) ) => {
161159 format ! ( "casting `{cast_from}` to `{cast_to}` may truncate the value" )
162160 } ,
163161
164- ( ty:: Float ( FloatTy :: F64 ) , false ) if matches ! ( cast_to. kind( ) , & ty:: Float ( FloatTy :: F32 ) ) => {
162+ ( ty:: Float ( FloatTy :: F64 ) , None ) if matches ! ( cast_to. kind( ) , & ty:: Float ( FloatTy :: F32 ) ) => {
165163 "casting `f64` to `f32` may truncate the value" . to_string ( )
166164 } ,
167165
0 commit comments