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:
commit
7eb025febf
|
@ -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)
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// check-pass
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
match &[0, 1] as &[i32] {
|
||||
[a @ .., x] => {}
|
||||
&[] => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue