Fix two const-eval issues related to i128 negation

First issue here was the fact that we’d only allow negating integers in i64 range in case the
integer was not infered yes. While this is not the direct cause of the issue, its still good to fix
it.

The real issue here is the code handling specifically the `min_value` literals. While I128_OVERFLOW
has the expected value (0x8000_..._0000), match using this value as a pattern is handled
incorrectly by the stage1 compiler (it seems to be handled correctly, by the stage2 compiler). So
what we do here is extract this pattern into an explicit `==` until the next snapshot.

Fixes #38987
This commit is contained in:
Simonas Kazlauskas 2017-01-11 16:28:23 +02:00
parent e57f061be2
commit e97f104da6
3 changed files with 31 additions and 14 deletions

View file

@ -661,7 +661,7 @@ impl ::std::ops::Neg for ConstInt {
a@U8(0) | a@U16(0) | a@U32(0) | a@U64(0) | a@U128(0) |
a@Usize(Us16(0)) | a@Usize(Us32(0)) | a@Usize(Us64(0)) => Ok(a),
U8(_) | U16(_) | U32(_) | U64(_) | U128(_) | Usize(_) => Err(UnsignedNegation),
Infer(a @ 0...ubounds::I64MAX) => Ok(InferSigned(-(a as i128))),
Infer(a @ 0...ubounds::I128MAX) => Ok(InferSigned(-(a as i128))),
Infer(_) => Err(Overflow(Op::Neg)),
InferSigned(a) => Ok(InferSigned(overflowing!(a.overflowing_neg(), Op::Neg))),
}