From b4b0744ce74a84cf6adc9d5cbf04351878c31db2 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 29 Oct 2018 15:22:47 +0100 Subject: [PATCH] Fix wrong validation clasisfication of `Option<&T>::Some` values --- src/librustc_mir/interpret/validity.rs | 2 +- src/test/ui/consts/const-validation-fail-55455.rs | 9 +++++++++ src/test/ui/consts/promoted-validation-55454.rs | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/const-validation-fail-55455.rs create mode 100644 src/test/ui/consts/promoted-validation-55454.rs diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index ac1ba0edc3b3b..c75fea4fde19c 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -289,7 +289,7 @@ 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 { + if (lo == 0 && hi == max_hi) || (hi + 1 == lo) { // Nothing to check return Ok(()); } diff --git a/src/test/ui/consts/const-validation-fail-55455.rs b/src/test/ui/consts/const-validation-fail-55455.rs new file mode 100644 index 0000000000000..def4062339f96 --- /dev/null +++ b/src/test/ui/consts/const-validation-fail-55455.rs @@ -0,0 +1,9 @@ +// https://github.com/rust-lang/rust/issues/55454 +// compile-pass + +struct This(T); + +const C: This> = This(Some(&1)); + +fn main() { +} diff --git a/src/test/ui/consts/promoted-validation-55454.rs b/src/test/ui/consts/promoted-validation-55454.rs new file mode 100644 index 0000000000000..5e193b1b7de0b --- /dev/null +++ b/src/test/ui/consts/promoted-validation-55454.rs @@ -0,0 +1,9 @@ +// https://github.com/rust-lang/rust/issues/55454 +// compile-pass + +#[derive(PartialEq)] +struct This(T); + +fn main() { + This(Some(&1)) == This(Some(&1)); +}