Skip to content

Commit 4a551ff

Browse files
authored
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
2 parents 286cb14 + 5b8df34 commit 4a551ff

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/librustc_mir/interpret/place.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,12 @@ where
530530
// This can only be reached in ConstProp and non-rustc-MIR.
531531
throw_ub!(BoundsCheckFailed { len: min_length as u64, index: n as u64 });
532532
}
533-
assert!(offset < min_length);
534533

535534
let index = if from_end {
535+
assert!(0 < offset && offset - 1 < min_length);
536536
n - u64::from(offset)
537537
} else {
538+
assert!(offset < min_length);
538539
u64::from(offset)
539540
};
540541

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
#![feature(slice_patterns)]
3+
4+
fn main() {
5+
match &[0, 1] as &[i32] {
6+
[a @ .., x] => {}
7+
&[] => {}
8+
}
9+
}

0 commit comments

Comments
 (0)