Skip to content

Commit 254552c

Browse files
committed
---
yaml --- r: 138416 b: refs/heads/try2 c: 8f8f0ec h: refs/heads/master v: v3
1 parent 125b640 commit 254552c

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
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: 423843e54bdbd6e32a0a75b7502904458e20c480
8+
refs/heads/try2: 8f8f0ec2c6761b096eea1f8dceb42c2618f5a196
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/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,7 @@ pub pure fn ty_fn_ret(fty: t) -> t {
28232823
}
28242824
}
28252825

2826-
fn is_fn_ty(fty: t) -> bool {
2826+
pub fn is_fn_ty(fty: t) -> bool {
28272827
match get(fty).sty {
28282828
ty_bare_fn(_) => true,
28292829
ty_closure(_) => true,

branches/try2/src/librustc/middle/typeck/check/_match.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
9292
match structure_of(pcx.fcx, pat.span, expected) {
9393
ty::ty_enum(_, ref expected_substs) => {
9494
// Lookup the enum and variant def ids:
95-
let v_def = lookup_def(pcx.fcx, path.span, pat.id);
95+
let v_def = lookup_def(pcx.fcx, pat.span, pat.id);
9696
let v_def_ids = ast_util::variant_def_ids(v_def);
9797

9898
// Assign the pattern the type of the *enum*, not the variant.
@@ -125,8 +125,17 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
125125
kind_name = "variant";
126126
}
127127
ty::ty_struct(struct_def_id, ref expected_substs) => {
128+
// Lookup the struct ctor def id
129+
let s_def = lookup_def(pcx.fcx, pat.span, pat.id);
130+
let s_def_id = ast_util::def_id_of_def(s_def);
131+
128132
// Assign the pattern the type of the struct.
129-
let struct_tpt = ty::lookup_item_type(tcx, struct_def_id);
133+
let ctor_tpt = ty::lookup_item_type(tcx, s_def_id);
134+
let struct_tpt = if ty::is_fn_ty(ctor_tpt.ty) {
135+
{ty: ty::ty_fn_ret(ctor_tpt.ty), ..ctor_tpt}
136+
} else {
137+
ctor_tpt
138+
};
130139
instantiate_path(pcx.fcx, path, struct_tpt, pat.span, pat.id,
131140
pcx.block_region);
132141

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern: mismatched types
2+
3+
struct S { a: int }
4+
enum E { C(int) }
5+
6+
fn main() {
7+
match S { a: 1 } {
8+
C(_) => (),
9+
_ => ()
10+
}
11+
}

0 commit comments

Comments
 (0)