diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-23 15:16:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-23 15:16:31 +0100 |
| commit | 7eb025febf48c294e376cedd4b57865792cefa99 (patch) | |
| tree | 9058e0c0c1ce9c467c01ede02c55a7362f5ef145 /src | |
| parent | 41647613b1a69e7df7490d23fee2823da249cda4 (diff) | |
| parent | 5b8df34203d1d6f308da7413c9f27b0b0887b438 (diff) | |
| download | rust-7eb025febf48c294e376cedd4b57865792cefa99.tar.gz rust-7eb025febf48c294e376cedd4b57865792cefa99.zip | |
Rollup merge of #67546 - oli-obk:slice_pattern_ice, r=varkor
Fix ICE in mir interpretation Indices from the end start at 1 so you can immediately subtract them from the length to get the index instead of having to do an additional `-1`. Kinda documented in https://doc.rust-lang.org/nightly/nightly-rustc/rustc/mir/enum.ProjectionElem.html#variant.ConstantIndex
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/interpret/place.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/consts/const_prop_slice_pat_ice.rs | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index a1e6eb69b9d..1141239e49a 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!(0 < offset && 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 00000000000..5fec36e44bd --- /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] => {} + &[] => {} + } +} |
