mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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:
@@ -530,11 +530,12 @@ pub fn mplace_projection(
|
||||
// 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] => {}
|
||||
&[] => {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user