Skip to content

Commit 4e29e81

Browse files
committed
Fix build
Additionally, revert unnecessary changes to ty::layout
1 parent 832d7e0 commit 4e29e81

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

src/librustc/ty/layout.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -382,25 +382,8 @@ impl Integer {
382382
}
383383
}
384384

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-
402385
/// 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 {
404387
match x {
405388
-0x0000_0000_0000_0001...0x0000_0000_0000_0000 => I1,
406389
-0x0000_0000_0000_0080...0x0000_0000_0000_007f => I8,
@@ -412,7 +395,7 @@ impl Integer {
412395
}
413396

414397
/// 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 {
416399
match x {
417400
0...0x0000_0000_0000_0001 => I1,
418401
0...0x0000_0000_0000_00ff => I8,
@@ -453,13 +436,13 @@ impl Integer {
453436
/// signed discriminant range and #[repr] attribute.
454437
/// N.B.: u64 values above i64::MAX will be treated as signed, but
455438
/// 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)
457440
-> (Integer, bool) {
458441
// Theoretically, negative values could be larger in unsigned representation
459442
// than the unsigned representation of the signed minimum. However, if there
460443
// are any negative values, the only valid unsigned representation is u64
461444
// 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));
463446
let signed_fit = cmp::max(Integer::fit_signed(min), Integer::fit_signed(max));
464447

465448
let mut min_from_extern = None;
@@ -472,7 +455,7 @@ impl Integer {
472455
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
473456
if discr < fit {
474457
bug!("Integer::repr_discr: `#[repr]` hint too small for \
475-
discriminant range of enum")
458+
discriminant range of enum `{}", ty)
476459
}
477460
return (discr, ity.is_signed());
478461
}
@@ -488,15 +471,16 @@ impl Integer {
488471
}
489472
attr::ReprAny => {},
490473
attr::ReprPacked => {
491-
bug!("Integer::repr_discr: found #[repr(packed)] on enum {}", ty);
474+
bug!("Integer::repr_discr: found #[repr(packed)] on enum `{}", ty);
492475
}
493476
attr::ReprSimd => {
494-
bug!("Integer::repr_discr: found #[repr(simd)] on enum {}", ty);
477+
bug!("Integer::repr_discr: found #[repr(simd)] on enum `{}", ty);
495478
}
496479
}
497480
}
498481

499482
let at_least = min_from_extern.unwrap_or(min_default);
483+
500484
// If there are no negative values, we can use the unsigned fit.
501485
if min >= 0 {
502486
(cmp::max(unsigned_fit, at_least), false)
@@ -1222,21 +1206,17 @@ impl<'a, 'gcx, 'tcx> Layout {
12221206
i64::min_value(),
12231207
true);
12241208
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;
12321210
if x == 0 { non_zero = false; }
12331211
if x < min { min = x; }
12341212
if x > max { max = x; }
12351213
}
12361214

12371215
// FIXME: should handle i128? signed-value based impl is weird and hard to
12381216
// 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);
12401220
return success(CEnum {
12411221
discr: discr,
12421222
signed: signed,
@@ -1354,6 +1334,7 @@ impl<'a, 'gcx, 'tcx> Layout {
13541334
let discr_max = (variants.len() - 1) as i64;
13551335
assert!(discr_max >= 0);
13561336
let (min_ity, _) = Integer::repr_discr(tcx, ty, &hints[..], 0, discr_max);
1337+
13571338
let mut align = dl.aggregate_align;
13581339
let mut size = Size::from_bytes(0);
13591340

0 commit comments

Comments
 (0)