Rollup merge of #55474 - oli-obk:const_eval_promoted, r=RalfJung

Fix validation false positive

Fixes #55454

r? @RalfJung
This commit is contained in:
kennytm 2018-10-30 18:55:32 +08:00 committed by GitHub
commit 3176239d34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View file

@ -576,7 +576,11 @@ pub fn const_eval_provider<'a, 'tcx>(
key.param_env.reveal = Reveal::UserFacing;
match tcx.const_eval(key) {
// try again with reveal all as requested
Err(ErrorHandled::TooGeneric) => {},
Err(ErrorHandled::TooGeneric) => {
// Promoteds should never be "too generic" when getting evaluated.
// They either don't get evaluated, or we are in a monomorphic context
assert!(key.value.promoted.is_none());
},
// dedupliate calls
other => return other,
}

View file

@ -303,7 +303,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
let (lo, hi) = layout.valid_range.clone().into_inner();
let max_hi = u128::max_value() >> (128 - size.bits()); // as big as the size fits
assert!(hi <= max_hi);
if lo == 0 && hi == max_hi {
// We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {
// Nothing to check
return Ok(());
}

View file

@ -0,0 +1,9 @@
// https://github.com/rust-lang/rust/issues/55454
// compile-pass
struct This<T>(T);
const C: This<Option<&i32>> = This(Some(&1));
fn main() {
}

View file

@ -0,0 +1,9 @@
// https://github.com/rust-lang/rust/issues/55454
// compile-pass
#[derive(PartialEq)]
struct This<T>(T);
fn main() {
This(Some(&1)) == This(Some(&1));
}