Avoid possible integer overflow in niche value computation

@eddyb pointed out in review that the niche value computation had a
possible integer overflow problem, fixed here as he suggested.
This commit is contained in:
Tom Tromey 2018-09-13 06:51:17 -06:00
parent e7c49a738e
commit da7b6b4b4d

View File

@ -1361,8 +1361,11 @@ fn compute_field_path<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
let niche_value = if i == dataful_variant {
None
} else {
Some((i.wrapping_sub(*niche_variants.start()) as u128)
.wrapping_add(niche_start) as u64)
let niche = (i as u128)
.wrapping_sub(*niche_variants.start() as u128)
.wrapping_add(niche_start);
assert_eq!(niche as u64 as u128, niche);
Some(niche as u64)
};
MemberDescription {