@@ -382,25 +382,8 @@ impl Integer {
382
382
}
383
383
}
384
384
385
- pub fn to_attr ( & self , signed : bool ) -> attr:: IntType {
386
- match ( * self , signed) {
387
- ( I1 , false ) => attr:: IntType :: UnsignedInt ( UintTy :: U8 ) ,
388
- ( I8 , false ) => attr:: IntType :: UnsignedInt ( UintTy :: U8 ) ,
389
- ( I16 , false ) => attr:: IntType :: UnsignedInt ( UintTy :: U16 ) ,
390
- ( I32 , false ) => attr:: IntType :: UnsignedInt ( UintTy :: U32 ) ,
391
- ( I64 , false ) => attr:: IntType :: UnsignedInt ( UintTy :: U64 ) ,
392
- ( I128 , false ) => attr:: IntType :: UnsignedInt ( UintTy :: U128 ) ,
393
- ( I1 , true ) => attr:: IntType :: SignedInt ( IntTy :: I8 ) ,
394
- ( I8 , true ) => attr:: IntType :: SignedInt ( IntTy :: I8 ) ,
395
- ( I16 , true ) => attr:: IntType :: SignedInt ( IntTy :: I16 ) ,
396
- ( I32 , true ) => attr:: IntType :: SignedInt ( IntTy :: I32 ) ,
397
- ( I64 , true ) => attr:: IntType :: SignedInt ( IntTy :: I64 ) ,
398
- ( I128 , true ) => attr:: IntType :: SignedInt ( IntTy :: I128 ) ,
399
- }
400
- }
401
-
402
385
/// Find the smallest Integer type which can represent the signed value.
403
- pub fn fit_signed ( x : i128 ) -> Integer {
386
+ pub fn fit_signed ( x : i64 ) -> Integer {
404
387
match x {
405
388
-0x0000_0000_0000_0001 ...0x0000_0000_0000_0000 => I1 ,
406
389
-0x0000_0000_0000_0080 ...0x0000_0000_0000_007f => I8 ,
@@ -412,7 +395,7 @@ impl Integer {
412
395
}
413
396
414
397
/// Find the smallest Integer type which can represent the unsigned value.
415
- pub fn fit_unsigned ( x : u128 ) -> Integer {
398
+ pub fn fit_unsigned ( x : u64 ) -> Integer {
416
399
match x {
417
400
0 ...0x0000_0000_0000_0001 => I1 ,
418
401
0 ...0x0000_0000_0000_00ff => I8 ,
@@ -453,13 +436,13 @@ impl Integer {
453
436
/// signed discriminant range and #[repr] attribute.
454
437
/// N.B.: u64 values above i64::MAX will be treated as signed, but
455
438
/// that shouldn't affect anything, other than maybe debuginfo.
456
- pub fn repr_discr ( tcx : TyCtxt , ty : Ty , hints : & [ attr:: ReprAttr ] , min : i128 , max : i128 )
439
+ fn repr_discr ( tcx : TyCtxt , ty : Ty , hints : & [ attr:: ReprAttr ] , min : i64 , max : i64 )
457
440
-> ( Integer , bool ) {
458
441
// Theoretically, negative values could be larger in unsigned representation
459
442
// than the unsigned representation of the signed minimum. However, if there
460
443
// are any negative values, the only valid unsigned representation is u64
461
444
// which can fit all i64 values, so the result remains unaffected.
462
- let unsigned_fit = Integer :: fit_unsigned ( cmp:: max ( min as u128 , max as u128 ) ) ;
445
+ let unsigned_fit = Integer :: fit_unsigned ( cmp:: max ( min as u64 , max as u64 ) ) ;
463
446
let signed_fit = cmp:: max ( Integer :: fit_signed ( min) , Integer :: fit_signed ( max) ) ;
464
447
465
448
let mut min_from_extern = None ;
@@ -472,7 +455,7 @@ impl Integer {
472
455
let fit = if ity. is_signed ( ) { signed_fit } else { unsigned_fit } ;
473
456
if discr < fit {
474
457
bug ! ( "Integer::repr_discr: `#[repr]` hint too small for \
475
- discriminant range of enum" )
458
+ discriminant range of enum `{}" , ty )
476
459
}
477
460
return ( discr, ity. is_signed ( ) ) ;
478
461
}
@@ -488,15 +471,16 @@ impl Integer {
488
471
}
489
472
attr:: ReprAny => { } ,
490
473
attr:: ReprPacked => {
491
- bug ! ( "Integer::repr_discr: found #[repr(packed)] on enum {}" , ty) ;
474
+ bug ! ( "Integer::repr_discr: found #[repr(packed)] on enum ` {}" , ty) ;
492
475
}
493
476
attr:: ReprSimd => {
494
- bug ! ( "Integer::repr_discr: found #[repr(simd)] on enum {}" , ty) ;
477
+ bug ! ( "Integer::repr_discr: found #[repr(simd)] on enum ` {}" , ty) ;
495
478
}
496
479
}
497
480
}
498
481
499
482
let at_least = min_from_extern. unwrap_or ( min_default) ;
483
+
500
484
// If there are no negative values, we can use the unsigned fit.
501
485
if min >= 0 {
502
486
( cmp:: max ( unsigned_fit, at_least) , false )
@@ -1222,21 +1206,17 @@ impl<'a, 'gcx, 'tcx> Layout {
1222
1206
i64:: min_value ( ) ,
1223
1207
true ) ;
1224
1208
for v in & def. variants {
1225
- let x = match def. discr_ty {
1226
- attr:: IntType :: SignedInt ( IntTy :: I128 ) |
1227
- attr:: IntType :: UnsignedInt ( UintTy :: U128 ) =>
1228
- bug ! ( "128-bit discriminants not yet supported" ) ,
1229
- attr:: IntType :: SignedInt ( _) => v. disr_val as i64 ,
1230
- attr:: IntType :: UnsignedInt ( _) => v. disr_val as u64 as i64 ,
1231
- } ;
1209
+ let x = v. disr_val as i128 as i64 ;
1232
1210
if x == 0 { non_zero = false ; }
1233
1211
if x < min { min = x; }
1234
1212
if x > max { max = x; }
1235
1213
}
1236
1214
1237
1215
// FIXME: should handle i128? signed-value based impl is weird and hard to
1238
1216
// grok.
1239
- let ( discr, signed) = Integer :: repr_discr ( tcx, ty, hints, min, max) ;
1217
+ let ( discr, signed) = Integer :: repr_discr ( tcx, ty, & hints[ ..] ,
1218
+ min,
1219
+ max) ;
1240
1220
return success ( CEnum {
1241
1221
discr : discr,
1242
1222
signed : signed,
@@ -1354,6 +1334,7 @@ impl<'a, 'gcx, 'tcx> Layout {
1354
1334
let discr_max = ( variants. len ( ) - 1 ) as i64 ;
1355
1335
assert ! ( discr_max >= 0 ) ;
1356
1336
let ( min_ity, _) = Integer :: repr_discr ( tcx, ty, & hints[ ..] , 0 , discr_max) ;
1337
+
1357
1338
let mut align = dl. aggregate_align ;
1358
1339
let mut size = Size :: from_bytes ( 0 ) ;
1359
1340
0 commit comments