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
This commit is contained in:
Mazdak Farrokhzad 2019-12-23 15:16:31 +01:00 committed by GitHub
commit 7eb025febf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -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)
};

View File

@ -0,0 +1,9 @@
// check-pass
#![feature(slice_patterns)]
fn main() {
match &[0, 1] as &[i32] {
[a @ .., x] => {}
&[] => {}
}
}