pat_id: ast::NodeId,
elem_count: uint,
slice: Option<uint>,
- val: ValueRef,
- count: ValueRef)
+ val: ValueRef)
-> ExtractedBlock<'a> {
let _icx = push_ctxt("match::extract_vec_elems");
let vec_datum = match_datum(bcx, val, pat_id);
Some(n) if i < n => GEPi(bcx, base, [i]),
Some(n) if i > n => {
InBoundsGEP(bcx, base, [
- Sub(bcx, count,
+ Sub(bcx, len,
C_int(bcx.ccx(), (elem_count - i) as int))])
}
_ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty.to_ref()) }
vec_len_eq => (n, None)
};
let args = extract_vec_elems(opt_cx, pat_id, n,
- slice, val, test_val);
+ slice, val);
size = args.vals.len();
unpacked = args.vals.clone();
opt_cx = args.bcx;
let loaded_val = Load(bcx, val);
bcx = bind_irrefutable_pat(bcx, inner, loaded_val, binding_mode, cleanup_scope);
}
- ast::PatVec(..) => {
- bcx.sess().span_bug(pat.span,
- "vector patterns are never irrefutable!");
+ ast::PatVec(ref before, ref slice, ref after) => {
+ let extracted = extract_vec_elems(
+ bcx, pat.id, before.len() + 1u + after.len(),
+ slice.map(|_| before.len()), val
+ );
+ bcx = before
+ .iter().map(|v| Some(*v))
+ .chain(Some(*slice).move_iter())
+ .chain(after.iter().map(|v| Some(*v)))
+ .zip(extracted.vals.iter())
+ .fold(bcx, |bcx, (inner, elem)| {
+ inner.map_or(bcx, |inner| {
+ bind_irrefutable_pat(bcx, inner, *elem, binding_mode, cleanup_scope)
+ })
+ });
}
ast::PatMac(..) => {
bcx.sess().span_bug(pat.span, "unexpanded macro");
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn foo<T: Add<T, T> + Clone>([x, y, z]: [T, ..3]) -> (T, T, T) {
+ (x.clone(), x.clone() + y.clone(), x + y + z)
+}
+fn bar(a: &'static str, b: &'static str) -> [&'static str, ..4] {
+ [a, b, b, a]
+}
+
+fn main() {
+ assert_eq!(foo([1, 2, 3]), (1, 3, 6));
+
+ let [a, b, c, d] = bar("foo", "bar");
+ assert_eq!(a, "foo");
+ assert_eq!(b, "bar");
+ assert_eq!(c, "bar");
+ assert_eq!(d, "foo");
+
+ let [a, _, _, d] = bar("baz", "foo");
+ assert_eq!(a, "baz");
+ assert_eq!(d, "baz");
+}
\ No newline at end of file