@@ -91,15 +91,14 @@ pub(super) fn check(
91
91
cast_to : Ty < ' _ > ,
92
92
cast_to_span : Span ,
93
93
) {
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 ) ) => {
96
96
let from_nbits = apply_reductions (
97
97
cx,
98
- utils:: int_ty_to_nbits ( cast_from , cx. tcx ) ,
98
+ utils:: int_ty_to_nbits ( cx. tcx , cast_from ) . unwrap ( ) ,
99
99
cast_expr,
100
100
cast_from. is_signed ( ) ,
101
101
) ;
102
- let to_nbits = utils:: int_ty_to_nbits ( cast_to, cx. tcx ) ;
103
102
104
103
let ( should_lint, suffix) = match ( is_isize_or_usize ( cast_from) , is_isize_or_usize ( cast_to) ) {
105
104
( true , true ) | ( false , false ) => ( to_nbits < from_nbits, "" ) ,
@@ -121,7 +120,7 @@ pub(super) fn check(
121
120
format ! ( "casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}" , )
122
121
} ,
123
122
124
- ( ty:: Adt ( def, _) , true ) if def. is_enum ( ) => {
123
+ ( ty:: Adt ( def, _) , Some ( to_nbits ) ) if def. is_enum ( ) => {
125
124
let ( from_nbits, variant) = if let ExprKind :: Path ( p) = & cast_expr. kind
126
125
&& let Res :: Def ( DefKind :: Ctor ( ..) , id) = cx. qpath_res ( p, cast_expr. hir_id )
127
126
{
@@ -132,7 +131,6 @@ pub(super) fn check(
132
131
} else {
133
132
( utils:: enum_ty_to_nbits ( * def, cx. tcx ) , None )
134
133
} ;
135
- let to_nbits = utils:: int_ty_to_nbits ( cast_to, cx. tcx ) ;
136
134
137
135
let cast_from_ptr_size = def. repr ( ) . int . is_none_or ( |ty| matches ! ( ty, IntegerType :: Pointer ( _) , ) ) ;
138
136
let suffix = match ( cast_from_ptr_size, is_isize_or_usize ( cast_to) ) {
@@ -157,11 +155,11 @@ pub(super) fn check(
157
155
format ! ( "casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}" )
158
156
} ,
159
157
160
- ( ty:: Float ( _) , true ) => {
158
+ ( ty:: Float ( _) , Some ( _ ) ) => {
161
159
format ! ( "casting `{cast_from}` to `{cast_to}` may truncate the value" )
162
160
} ,
163
161
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 ) ) => {
165
163
"casting `f64` to `f32` may truncate the value" . to_string ( )
166
164
} ,
167
165
0 commit comments