Fix panic in subslice patterns of arrays (fixes #276)

This commit is contained in:
Oliver Schneider 2017-08-29 09:55:40 +02:00
parent b8329da5e8
commit 206f0bd6df
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 20 additions and 1 deletions

View file

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

View 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");
}