diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-10-29 15:22:47 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-10-29 15:22:47 +0100 |
| commit | 3ad154f4842e9a1f09b5da37a76a333691f31784 (patch) | |
| tree | 94eb6587ad8a0685aa68a29a3b981633daaa5364 | |
| parent | e0106d99d699bbb427f4ebb156a343cc26159e11 (diff) | |
| download | rust-3ad154f4842e9a1f09b5da37a76a333691f31784.tar.gz rust-3ad154f4842e9a1f09b5da37a76a333691f31784.zip | |
Fix wrong validation clasisfication of `Option<&T>::Some` values
| -rw-r--r-- | src/librustc_mir/interpret/validity.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/consts/const-validation-fail-55455.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/consts/promoted-validation-55454.rs | 9 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 226717538a2..982f3dab108 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -303,7 +303,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 00000000000..def4062339f --- /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>(T); + +const C: This<Option<&i32>> = 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 00000000000..5e193b1b7de --- /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>(T); + +fn main() { + This(Some(&1)) == This(Some(&1)); +} |
