@@ -9,7 +9,6 @@ use rustc_middle::ty::adjustment::PointerCoercion;
9
9
use rustc_middle:: ty:: layout:: { IntegerExt , LayoutOf , TyAndLayout } ;
10
10
use rustc_middle:: ty:: { self , FloatTy , Ty } ;
11
11
use rustc_middle:: { bug, span_bug} ;
12
- use rustc_type_ir:: TyKind :: * ;
13
12
use tracing:: trace;
14
13
15
14
use super :: util:: ensure_monomorphic_enough;
@@ -182,9 +181,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
182
181
src : & ImmTy < ' tcx , M :: Provenance > ,
183
182
cast_to : TyAndLayout < ' tcx > ,
184
183
) -> InterpResult < ' tcx , ImmTy < ' tcx , M :: Provenance > > {
185
- use rustc_type_ir:: TyKind :: * ;
186
-
187
- let Float ( fty) = src. layout . ty . kind ( ) else {
184
+ let ty:: Float ( fty) = src. layout . ty . kind ( ) else {
188
185
bug ! ( "FloatToFloat/FloatToInt cast: source type {} is not a float type" , src. layout. ty)
189
186
} ;
190
187
let val = match fty {
@@ -277,27 +274,27 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
277
274
let signed = src_layout. backend_repr . is_signed ( ) ; // Also asserts that abi is `Scalar`.
278
275
279
276
let v = match src_layout. ty . kind ( ) {
280
- Uint ( _) | RawPtr ( ..) | FnPtr ( ..) => scalar. to_uint ( src_layout. size ) ?,
281
- Int ( _) => scalar. to_int ( src_layout. size ) ? as u128 , // we will cast back to `i128` below if the sign matters
282
- Bool => scalar. to_bool ( ) ?. into ( ) ,
283
- Char => scalar. to_char ( ) ?. into ( ) ,
277
+ ty :: Uint ( _) | ty :: RawPtr ( ..) | ty :: FnPtr ( ..) => scalar. to_uint ( src_layout. size ) ?,
278
+ ty :: Int ( _) => scalar. to_int ( src_layout. size ) ? as u128 , // we will cast back to `i128` below if the sign matters
279
+ ty :: Bool => scalar. to_bool ( ) ?. into ( ) ,
280
+ ty :: Char => scalar. to_char ( ) ?. into ( ) ,
284
281
_ => span_bug ! ( self . cur_span( ) , "invalid int-like cast from {}" , src_layout. ty) ,
285
282
} ;
286
283
287
284
interp_ok ( match * cast_ty. kind ( ) {
288
285
// int -> int
289
- Int ( _) | Uint ( _) => {
286
+ ty :: Int ( _) | ty :: Uint ( _) => {
290
287
let size = match * cast_ty. kind ( ) {
291
- Int ( t) => Integer :: from_int_ty ( self , t) . size ( ) ,
292
- Uint ( t) => Integer :: from_uint_ty ( self , t) . size ( ) ,
288
+ ty :: Int ( t) => Integer :: from_int_ty ( self , t) . size ( ) ,
289
+ ty :: Uint ( t) => Integer :: from_uint_ty ( self , t) . size ( ) ,
293
290
_ => bug ! ( ) ,
294
291
} ;
295
292
let v = size. truncate ( v) ;
296
293
Scalar :: from_uint ( v, size)
297
294
}
298
295
299
296
// signed int -> float
300
- Float ( fty) if signed => {
297
+ ty :: Float ( fty) if signed => {
301
298
let v = v as i128 ;
302
299
match fty {
303
300
FloatTy :: F16 => Scalar :: from_f16 ( Half :: from_i128 ( v) . value ) ,
@@ -307,15 +304,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
307
304
}
308
305
}
309
306
// unsigned int -> float
310
- Float ( fty) => match fty {
307
+ ty :: Float ( fty) => match fty {
311
308
FloatTy :: F16 => Scalar :: from_f16 ( Half :: from_u128 ( v) . value ) ,
312
309
FloatTy :: F32 => Scalar :: from_f32 ( Single :: from_u128 ( v) . value ) ,
313
310
FloatTy :: F64 => Scalar :: from_f64 ( Double :: from_u128 ( v) . value ) ,
314
311
FloatTy :: F128 => Scalar :: from_f128 ( Quad :: from_u128 ( v) . value ) ,
315
312
} ,
316
313
317
314
// u8 -> char
318
- Char => Scalar :: from_u32 ( u8:: try_from ( v) . unwrap ( ) . into ( ) ) ,
315
+ ty :: Char => Scalar :: from_u32 ( u8:: try_from ( v) . unwrap ( ) . into ( ) ) ,
319
316
320
317
// Casts to bool are not permitted by rustc, no need to handle them here.
321
318
_ => span_bug ! ( self . cur_span( ) , "invalid int to {} cast" , cast_ty) ,
@@ -332,11 +329,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
332
329
+ FloatConvert < Double >
333
330
+ FloatConvert < Quad > ,
334
331
{
335
- use rustc_type_ir:: TyKind :: * ;
336
-
337
332
match * dest_ty. kind ( ) {
338
333
// float -> uint
339
- Uint ( t) => {
334
+ ty :: Uint ( t) => {
340
335
let size = Integer :: from_uint_ty ( self , t) . size ( ) ;
341
336
// `to_u128` is a saturating cast, which is what we need
342
337
// (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r).
@@ -345,15 +340,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
345
340
Scalar :: from_uint ( v, size)
346
341
}
347
342
// float -> int
348
- Int ( t) => {
343
+ ty :: Int ( t) => {
349
344
let size = Integer :: from_int_ty ( self , t) . size ( ) ;
350
345
// `to_i128` is a saturating cast, which is what we need
351
346
// (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r).
352
347
let v = f. to_i128 ( size. bits_usize ( ) ) . value ;
353
348
Scalar :: from_int ( v, size)
354
349
}
355
350
// float -> float
356
- Float ( fty) => match fty {
351
+ ty :: Float ( fty) => match fty {
357
352
FloatTy :: F16 => {
358
353
Scalar :: from_f16 ( self . adjust_nan ( f. convert ( & mut false ) . value , & [ f] ) )
359
354
}
0 commit comments