Skip to content

Commit 30d1339

Browse files
author
Jakub Wieczorek
committed
---
yaml --- r: 152710 b: refs/heads/try2 c: 1e68d57 h: refs/heads/master v: v3
1 parent 58fd2ff commit 30d1339

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 34407dcdbb489a38b15fac0167a88cb94c3d12ac
8+
refs/heads/try2: 1e68d576829c09a64dd2f0ac802165a8e3376ac2
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/_match.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,7 @@ fn extract_vec_elems<'a>(
988988
pat_id: ast::NodeId,
989989
elem_count: uint,
990990
slice: Option<uint>,
991-
val: ValueRef,
992-
count: ValueRef)
991+
val: ValueRef)
993992
-> ExtractedBlock<'a> {
994993
let _icx = push_ctxt("match::extract_vec_elems");
995994
let vec_datum = match_datum(bcx, val, pat_id);
@@ -1003,7 +1002,7 @@ fn extract_vec_elems<'a>(
10031002
Some(n) if i < n => GEPi(bcx, base, [i]),
10041003
Some(n) if i > n => {
10051004
InBoundsGEP(bcx, base, [
1006-
Sub(bcx, count,
1005+
Sub(bcx, len,
10071006
C_int(bcx.ccx(), (elem_count - i) as int))])
10081007
}
10091008
_ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty.to_ref()) }
@@ -1765,7 +1764,7 @@ fn compile_submatch_continue<'a, 'b>(
17651764
vec_len_eq => (n, None)
17661765
};
17671766
let args = extract_vec_elems(opt_cx, pat_id, n,
1768-
slice, val, test_val);
1767+
slice, val);
17691768
size = args.vals.len();
17701769
unpacked = args.vals.clone();
17711770
opt_cx = args.bcx;
@@ -2264,9 +2263,21 @@ fn bind_irrefutable_pat<'a>(
22642263
let loaded_val = Load(bcx, val);
22652264
bcx = bind_irrefutable_pat(bcx, inner, loaded_val, binding_mode, cleanup_scope);
22662265
}
2267-
ast::PatVec(..) => {
2268-
bcx.sess().span_bug(pat.span,
2269-
"vector patterns are never irrefutable!");
2266+
ast::PatVec(ref before, ref slice, ref after) => {
2267+
let extracted = extract_vec_elems(
2268+
bcx, pat.id, before.len() + 1u + after.len(),
2269+
slice.map(|_| before.len()), val
2270+
);
2271+
bcx = before
2272+
.iter().map(|v| Some(*v))
2273+
.chain(Some(*slice).move_iter())
2274+
.chain(after.iter().map(|v| Some(*v)))
2275+
.zip(extracted.vals.iter())
2276+
.fold(bcx, |bcx, (inner, elem)| {
2277+
inner.map_or(bcx, |inner| {
2278+
bind_irrefutable_pat(bcx, inner, *elem, binding_mode, cleanup_scope)
2279+
})
2280+
});
22702281
}
22712282
ast::PatMac(..) => {
22722283
bcx.sess().span_bug(pat.span, "unexpanded macro");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn foo<T: Add<T, T> + Clone>([x, y, z]: [T, ..3]) -> (T, T, T) {
12+
(x.clone(), x.clone() + y.clone(), x + y + z)
13+
}
14+
fn bar(a: &'static str, b: &'static str) -> [&'static str, ..4] {
15+
[a, b, b, a]
16+
}
17+
18+
fn main() {
19+
assert_eq!(foo([1, 2, 3]), (1, 3, 6));
20+
21+
let [a, b, c, d] = bar("foo", "bar");
22+
assert_eq!(a, "foo");
23+
assert_eq!(b, "bar");
24+
assert_eq!(c, "bar");
25+
assert_eq!(d, "foo");
26+
27+
let [a, _, _, d] = bar("baz", "foo");
28+
assert_eq!(a, "baz");
29+
assert_eq!(d, "baz");
30+
}

0 commit comments

Comments
 (0)