diff options
| author | bors <bors@rust-lang.org> | 2013-02-27 12:21:49 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-02-27 12:21:49 -0800 |
| commit | 5fc0eccdfa1c81d9759b0592e5b86b0ff7fd4fa8 (patch) | |
| tree | 0de77c13138024b6ebc9e6e371ccdb8603043d3a /src | |
| parent | a6d9689399d091c3265f00434a69c551a61c28dc (diff) | |
| parent | 35baf5b2021fab393ff4d52581c55a0f6477bfb8 (diff) | |
| download | rust-5fc0eccdfa1c81d9759b0592e5b86b0ff7fd4fa8.tar.gz rust-5fc0eccdfa1c81d9759b0592e5b86b0ff7fd4fa8.zip | |
auto merge of #5070 : youknowone/rust/struct-match2, r=nikomatsakis
It is reversed that type of arm pattern and type of search pattern in error message.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/typeck/check/_match.rs | 8 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/demand.rs | 17 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/mod.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-3680.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/match-struct.rs | 3 |
5 files changed, 19 insertions, 14 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 82f9828db3f..795ea4323fe 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -103,7 +103,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, // check that the type of the value being matched is a subtype // of the type of the pattern: let pat_ty = fcx.node_ty(pat.id); - demand::suptype(fcx, pat.span, pat_ty, expected); + demand::subtype(fcx, pat.span, expected, pat_ty); // Get the expected types of the arguments. arg_types = { @@ -142,7 +142,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, // Check that the type of the value being matched is a subtype of // the type of the pattern. let pat_ty = fcx.node_ty(pat.id); - demand::suptype(fcx, pat.span, pat_ty, expected); + demand::subtype(fcx, pat.span, expected, pat_ty); // Get the expected types of the arguments. let class_fields = ty::struct_fields( @@ -154,8 +154,8 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, _ => { tcx.sess.span_fatal( pat.span, - fmt!("mismatched types: expected enum or structure but \ - found `%s`", + fmt!("mismatched types: expected `%s` but found enum or \ + structure", fcx.infcx().ty_to_str(expected))); } } diff --git a/src/librustc/middle/typeck/check/demand.rs b/src/librustc/middle/typeck/check/demand.rs index 5f1a3b5c17c..a3fac8b4e1c 100644 --- a/src/librustc/middle/typeck/check/demand.rs +++ b/src/librustc/middle/typeck/check/demand.rs @@ -21,20 +21,25 @@ use syntax::codemap::span; // Requires that the two types unify, and prints an error message if they // don't. pub fn suptype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) { - suptype_with_fn(fcx, sp, expected, actual, + suptype_with_fn(fcx, sp, false, expected, actual, |sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) }) } +pub fn subtype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) { + suptype_with_fn(fcx, sp, true, actual, expected, + |sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) }) +} + pub fn suptype_with_fn(fcx: @mut FnCtxt, - sp: span, - expected: ty::t, actual: ty::t, + sp: span, b_is_expected: bool, + ty_a: ty::t, ty_b: ty::t, handle_err: fn(span, ty::t, ty::t, &ty::type_err)) { // n.b.: order of actual, expected is reversed - match infer::mk_subty(fcx.infcx(), false, sp, - actual, expected) { + match infer::mk_subty(fcx.infcx(), b_is_expected, sp, + ty_b, ty_a) { result::Ok(()) => { /* ok */ } result::Err(ref err) => { - handle_err(sp, expected, actual, err); + handle_err(sp, ty_a, ty_b, err); } } } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 998c007c86d..17f3cc515e8 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -355,7 +355,8 @@ pub fn check_fn(ccx: @mut CrateCtxt, let tail_expr_ty = fcx.expr_ty(tail_expr); // Special case: we print a special error if there appears // to be do-block/for-loop confusion - demand::suptype_with_fn(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty, + demand::suptype_with_fn(fcx, tail_expr.span, false, + fcx.ret_ty, tail_expr_ty, |sp, e, a, s| { fcx.report_mismatched_return_types(sp, e, a, s) }); } diff --git a/src/test/compile-fail/issue-3680.rs b/src/test/compile-fail/issue-3680.rs index 9044c6b6d79..18b5d290f3d 100644 --- a/src/test/compile-fail/issue-3680.rs +++ b/src/test/compile-fail/issue-3680.rs @@ -10,6 +10,6 @@ fn main() { match None { - Err(_) => () //~ ERROR expected `core::result + Err(_) => () //~ ERROR mismatched types: expected `core::option::Option<<V1>>` but found `core::result::Result<<V2>,<V3>>` } } diff --git a/src/test/compile-fail/match-struct.rs b/src/test/compile-fail/match-struct.rs index fa406aa278e..6e9bf603aef 100644 --- a/src/test/compile-fail/match-struct.rs +++ b/src/test/compile-fail/match-struct.rs @@ -1,11 +1,10 @@ -// error-pattern: mismatched types struct S { a: int } enum E { C(int) } fn main() { match S { a: 1 } { - C(_) => (), + C(_) => (), //~ ERROR mismatched types: expected `S` but found `E` _ => () } } |
