Skip to content

Commit 5ecac0a

Browse files
author
Jakub Wieczorek
committed
---
yaml --- r: 152711 b: refs/heads/try2 c: 9dca26c h: refs/heads/master i: 152709: 58fd2ff 152707: 31223e7 152703: bf55bd9 v: v3
1 parent 30d1339 commit 5ecac0a

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
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: 1e68d576829c09a64dd2f0ac802165a8e3376ac2
8+
refs/heads/try2: 9dca26cf92b26ea878b142430d2309919a85aee6
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/typeck/check/_match.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
632632
fcx.infcx().next_region_var(
633633
infer::PatternRegion(pat.span));
634634

635-
let check_err = || {
636-
for elt in before.iter() {
637-
check_pat(pcx, &**elt, ty::mk_err());
635+
let check_err = |found: String| {
636+
for &elt in before.iter() {
637+
check_pat(pcx, &*elt, ty::mk_err());
638638
}
639639
for elt in slice.iter() {
640640
check_pat(pcx, &**elt, ty::mk_err());
@@ -653,15 +653,16 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
653653
})
654654
},
655655
Some(expected),
656-
"a vector pattern".to_string(),
656+
found,
657657
None);
658658
fcx.write_error(pat.id);
659659
};
660660

661-
let (elt_type, region_var, mutbl) = match *structure_of(fcx,
661+
let (elt_type, region_var, mutbl, fixed) = match *structure_of(fcx,
662662
pat.span,
663663
expected) {
664-
ty::ty_vec(mt, Some(_)) => (mt.ty, default_region_var, ast::MutImmutable),
664+
ty::ty_vec(mt, Some(fixed)) =>
665+
(mt.ty, default_region_var, ast::MutImmutable, Some(fixed)),
665666
ty::ty_uniq(t) => match ty::get(t).sty {
666667
ty::ty_vec(mt, None) => {
667668
fcx.type_error_message(pat.span,
@@ -671,25 +672,40 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
671672
},
672673
expected,
673674
None);
674-
(mt.ty, default_region_var, ast::MutImmutable)
675+
(mt.ty, default_region_var, ast::MutImmutable, None)
675676
}
676677
_ => {
677-
check_err();
678+
check_err("a vector pattern".to_string());
678679
return;
679680
}
680681
},
681682
ty::ty_rptr(r, mt) => match ty::get(mt.ty).sty {
682-
ty::ty_vec(mt, None) => (mt.ty, r, mt.mutbl),
683+
ty::ty_vec(mt, None) => (mt.ty, r, mt.mutbl, None),
683684
_ => {
684-
check_err();
685+
check_err("a vector pattern".to_string());
685686
return;
686687
}
687688
},
688689
_ => {
689-
check_err();
690+
check_err("a vector pattern".to_string());
690691
return;
691692
}
692693
};
694+
695+
let min_len = before.len() + after.len();
696+
fixed.and_then(|count| match slice {
697+
Some(_) if count < min_len =>
698+
Some(format!("a fixed vector pattern of size at least {}", min_len)),
699+
700+
None if count != min_len =>
701+
Some(format!("a fixed vector pattern of size {}", min_len)),
702+
703+
_ => None
704+
}).and_then(|message| {
705+
check_err(message);
706+
Some(())
707+
});
708+
693709
for elt in before.iter() {
694710
check_pat(pcx, &**elt, elt_type);
695711
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 main() {
12+
let x = [1,2];
13+
let y = match x {
14+
[] => None,
15+
//~^ ERROR expected `[<generic integer #1>, .. 2]` but found a fixed vector pattern of size 0
16+
[a,_] => Some(a)
17+
};
18+
}

0 commit comments

Comments
 (0)