Skip to content

Fix validation false positive #55474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/consts/const-validation-fail-55455.rs
Original file line number Diff line number Diff line change
@@ -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() {
}
9 changes: 9 additions & 0 deletions src/test/ui/consts/promoted-validation-55454.rs
Original file line number Diff line number Diff line change
@@ -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));
}