Fix panic in subslice patterns of arrays (fixes #276)
This commit is contained in:
parent
b8329da5e8
commit
206f0bd6df
2 changed files with 20 additions and 1 deletions
|
|
@ -476,7 +476,12 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
|||
);
|
||||
assert!(u64::from(from) <= n - u64::from(to));
|
||||
let ptr = base_ptr.offset(u64::from(from) * elem_size, &self)?;
|
||||
let extra = LvalueExtra::Length(n - u64::from(to) - u64::from(from));
|
||||
// sublicing arrays produces arrays
|
||||
let extra = if self.type_is_sized(base_ty) {
|
||||
LvalueExtra::None
|
||||
} else {
|
||||
LvalueExtra::Length(n - u64::from(to) - u64::from(from))
|
||||
};
|
||||
(ptr, extra)
|
||||
}
|
||||
};
|
||||
|
|
|
|||
14
tests/run-pass/subslice_array.rs
Normal file
14
tests/run-pass/subslice_array.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn bar(a: &'static str, b: &'static str) -> [&'static str; 4] {
|
||||
[a, b, b, a]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let out = bar("baz", "foo");
|
||||
let [a, xs.., d] = out;
|
||||
assert_eq!(a, "baz");
|
||||
assert_eq!(xs, ["foo", "foo"]);
|
||||
assert_eq!(d, "baz");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue