@@ -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 , repr : & ReprOptions , min : i128 , max : i128 )
439
+ fn repr_discr ( tcx : TyCtxt , ty : Ty , repr : & ReprOptions , 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 ;
@@ -487,6 +470,7 @@ impl Integer {
487
470
}
488
471
489
472
let at_least = min_from_extern. unwrap_or ( min_default) ;
473
+
490
474
// If there are no negative values, we can use the unsigned fit.
491
475
if min >= 0 {
492
476
( cmp:: max ( unsigned_fit, at_least) , false )
@@ -1198,21 +1182,17 @@ impl<'a, 'gcx, 'tcx> Layout {
1198
1182
i64:: min_value ( ) ,
1199
1183
true ) ;
1200
1184
for v in & def. variants {
1201
- let x = match def. discr_ty {
1202
- attr:: IntType :: SignedInt ( IntTy :: I128 ) |
1203
- attr:: IntType :: UnsignedInt ( UintTy :: U128 ) =>
1204
- bug ! ( "128-bit discriminants not yet supported" ) ,
1205
- attr:: IntType :: SignedInt ( _) => v. disr_val as i64 ,
1206
- attr:: IntType :: UnsignedInt ( _) => v. disr_val as u64 as i64 ,
1207
- } ;
1185
+ let x = v. disr_val as i128 as i64 ;
1208
1186
if x == 0 { non_zero = false ; }
1209
1187
if x < min { min = x; }
1210
1188
if x > max { max = x; }
1211
1189
}
1212
1190
1213
1191
// FIXME: should handle i128? signed-value based impl is weird and hard to
1214
1192
// grok.
1215
- let ( discr, signed) = Integer :: repr_discr ( tcx, ty, hints, min, max) ;
1193
+ let ( discr, signed) = Integer :: repr_discr ( tcx, ty, & hints[ ..] ,
1194
+ min,
1195
+ max) ;
1216
1196
return success ( CEnum {
1217
1197
discr : discr,
1218
1198
signed : signed,
@@ -1330,6 +1310,7 @@ impl<'a, 'gcx, 'tcx> Layout {
1330
1310
let discr_max = ( variants. len ( ) - 1 ) as i64 ;
1331
1311
assert ! ( discr_max >= 0 ) ;
1332
1312
let ( min_ity, _) = Integer :: repr_discr ( tcx, ty, & hints[ ..] , 0 , discr_max) ;
1313
+
1333
1314
let mut align = dl. aggregate_align ;
1334
1315
let mut size = Size :: from_bytes ( 0 ) ;
1335
1316
0 commit comments