From 056dff5748270249d81a03b355bc7ddd8da7f900 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 23 Dec 2019 01:24:11 +0100 Subject: [PATCH 1/2] Fix ICE in mir interpretation --- src/librustc_mir/interpret/place.rs | 3 ++- src/test/ui/consts/const_prop_slice_pat_ice.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/const_prop_slice_pat_ice.rs diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 8923b167fdee8..6e7fa302abcbb 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -530,11 +530,12 @@ where // This can only be reached in ConstProp and non-rustc-MIR. throw_ub!(BoundsCheckFailed { len: min_length as u64, index: n as u64 }); } - assert!(offset < min_length); let index = if from_end { + assert!(offset - 1 < min_length); n - u64::from(offset) } else { + assert!(offset < min_length); u64::from(offset) }; diff --git a/src/test/ui/consts/const_prop_slice_pat_ice.rs b/src/test/ui/consts/const_prop_slice_pat_ice.rs new file mode 100644 index 0000000000000..5fec36e44bd8c --- /dev/null +++ b/src/test/ui/consts/const_prop_slice_pat_ice.rs @@ -0,0 +1,9 @@ +// check-pass +#![feature(slice_patterns)] + +fn main() { + match &[0, 1] as &[i32] { + [a @ .., x] => {} + &[] => {} + } +} From 5b8df34203d1d6f308da7413c9f27b0b0887b438 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 23 Dec 2019 11:27:34 +0100 Subject: [PATCH 2/2] Update src/librustc_mir/interpret/place.rs Co-Authored-By: Ralf Jung --- src/librustc_mir/interpret/place.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 6e7fa302abcbb..37540d8a3ccb1 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -532,7 +532,7 @@ where } let index = if from_end { - assert!(offset - 1 < min_length); + assert!(0 < offset && offset - 1 < min_length); n - u64::from(offset) } else { assert!(offset < min_length);