@@ -7,7 +7,7 @@ use clippy_utils::ty::is_isize_or_usize;
77use  rustc_errors:: Applicability ; 
88use  rustc_hir:: { Expr ,  QPath ,  TyKind } ; 
99use  rustc_lint:: LateContext ; 
10- use  rustc_middle:: ty:: { self ,  FloatTy ,   Ty } ; 
10+ use  rustc_middle:: ty:: { self ,  Ty } ; 
1111use  rustc_span:: hygiene; 
1212
1313use  super :: { CAST_LOSSLESS ,  utils} ; 
@@ -76,29 +76,42 @@ fn should_lint(cx: &LateContext<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: M
7676        return  false ; 
7777    } 
7878
79-     match  ( cast_from. is_integral ( ) ,  cast_to. is_integral ( ) )  { 
80-         ( true ,  true )  => { 
81-             let  cast_signed_to_unsigned = cast_from. is_signed ( )  && !cast_to. is_signed ( ) ; 
82-             let  from_nbits = utils:: int_ty_to_nbits ( cast_from,  cx. tcx ) ; 
83-             let  to_nbits = utils:: int_ty_to_nbits ( cast_to,  cx. tcx ) ; 
84-             !is_isize_or_usize ( cast_from) 
85-                 && !is_isize_or_usize ( cast_to) 
86-                 && from_nbits < to_nbits
87-                 && !cast_signed_to_unsigned
88-         } , 
79+     if  matches ! ( cast_from. kind( ) ,  ty:: Bool )  && cast_to. is_integral ( )  { 
80+         return  msrv. meets ( cx,  msrvs:: FROM_BOOL ) ; 
81+     } 
8982
90-         ( true ,  false )  => { 
91-             let  from_nbits = utils:: int_ty_to_nbits ( cast_from,  cx. tcx ) ; 
92-             let  to_nbits = if  let  ty:: Float ( FloatTy :: F32 )  = cast_to. kind ( )  { 
93-                 32 
94-             }  else  { 
95-                 64 
96-             } ; 
97-             !is_isize_or_usize ( cast_from)  && from_nbits < to_nbits
98-         } , 
99-         ( false ,  true )  if  matches ! ( cast_from. kind( ) ,  ty:: Bool )  && msrv. meets ( cx,  msrvs:: FROM_BOOL )  => true , 
100-         ( _,  _)  => { 
101-             matches ! ( cast_from. kind( ) ,  ty:: Float ( FloatTy :: F32 ) )  && matches ! ( cast_to. kind( ) ,  ty:: Float ( FloatTy :: F64 ) ) 
102-         } , 
83+     if  cast_from. is_numeric ( )  { 
84+         return  match  ( cast_from. is_integral ( ) ,  cast_to. is_integral ( ) )  { 
85+             ( true ,  true )  => { 
86+                 let  cast_signed_to_unsigned = cast_from. is_signed ( )  && !cast_to. is_signed ( ) ; 
87+                 let  from_nbits = utils:: int_ty_to_nbits ( cast_from,  cx. tcx ) ; 
88+                 let  to_nbits = utils:: int_ty_to_nbits ( cast_to,  cx. tcx ) ; 
89+                 !is_isize_or_usize ( cast_from) 
90+                     && !is_isize_or_usize ( cast_to) 
91+                     && from_nbits < to_nbits
92+                     && !cast_signed_to_unsigned
93+             } , 
94+             ( true ,  false )  => { 
95+                 let  from_nbits = utils:: int_ty_to_nbits ( cast_from,  cx. tcx ) ; 
96+                 let  to_nbits = utils:: float_ty_to_nbits ( cast_to) ; 
97+                 if  from_nbits == 64  && to_nbits == 128  { 
98+                     // FIXME(f16_f128): https://github.com/rust-lang/rust/blob/91fad92585b2dafc52a074e502b2a6c1f093ca35/library/core/src/convert/num.rs#L171 
99+                     return  false ; 
100+                 } 
101+                 !is_isize_or_usize ( cast_from)  && from_nbits < to_nbits
102+             } , 
103+             ( false ,  true )  => false , 
104+             ( false ,  false )  => { 
105+                 let  from_nbits = utils:: float_ty_to_nbits ( cast_from) ; 
106+                 let  to_nbits = utils:: float_ty_to_nbits ( cast_to) ; 
107+                 if  from_nbits == 16  && to_nbits == 32  { 
108+                     // FIXME(f16_f128): https://github.com/rust-lang/rust/issues/123831 
109+                     return  false ; 
110+                 } 
111+                 from_nbits < to_nbits
112+             } , 
113+         } ; 
103114    } 
115+ 
116+     false 
104117} 
0 commit comments