Skip to content

Commit df26355

Browse files
author
Jakub Wieczorek
committed
---
yaml --- r: 118523 b: refs/heads/master c: 1e68d57 h: refs/heads/master i: 118521: 025a9b5 118519: d73c310 v: v3
1 parent 7a40c10 commit df26355

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 34407dcdbb489a38b15fac0167a88cb94c3d12ac
2+
refs/heads/master: 1e68d576829c09a64dd2f0ac802165a8e3376ac2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: d6736a1440d42f6af967a8a20ab8d73522112b72
55
refs/heads/try: 04eced750e78770e16354c07fddf7ecaaab6ef43

trunk/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");

trunk/src/test/run-pass/issue-7784.rs

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)