@@ -1402,59 +1402,13 @@ fn require_same_types(
1402
1402
}
1403
1403
1404
1404
mod demand {
1405
- fn simple(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t) ->
1406
- ty::t {
1407
- full(fcx, sp, unify::unify, expected, actual, []).ty
1408
- }
1409
-
1410
- // n.b.: order of arguments is reversed.
1411
- fn subty(fcx: @fn_ctxt, sp: span, actual: ty::t, expected: ty::t) {
1412
- full(fcx, sp, unify::unify, expected, actual, []);
1413
- }
1414
-
1415
- fn with_substs(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t,
1416
- ty_param_substs_0: [ty::t]) -> ty_param_substs_and_ty {
1417
- full(fcx, sp, unify::unify, expected, actual, ty_param_substs_0)
1418
- }
1419
-
1420
1405
// Requires that the two types unify, and prints an error message if they
1421
- // don't. Returns the unified type and the type parameter substitutions.
1422
- fn full(fcx: @fn_ctxt,
1423
- sp: span,
1424
- unifier: fn@(@fn_ctxt, ty::t, ty::t)
1425
- -> result<(), ty::type_err>,
1426
- expected: ty::t,
1427
- actual: ty::t,
1428
- ty_param_substs_0: [ty::t]) ->
1429
- ty_param_substs_and_ty {
1430
-
1431
- let mut ty_param_substs: [mut ty::t] = [mut];
1432
- let mut ty_param_subst_var_ids: [ty_vid] = [];
1433
- for ty_param_substs_0.each {|ty_param_subst|
1434
- // Generate a type variable and unify it with the type parameter
1435
- // substitution. We will then pull out these type variables.
1436
- let t_0 = next_ty_var(fcx);
1437
- ty_param_substs += [mut t_0];
1438
- ty_param_subst_var_ids += [ty::ty_var_id(t_0)];
1439
- simple(fcx, sp, ty_param_subst, t_0);
1440
- }
1441
-
1442
- fn mk_result(fcx: @fn_ctxt, result_ty: ty::t,
1443
- ty_param_subst_var_ids: [ty_vid]) ->
1444
- ty_param_substs_and_ty {
1445
- let mut result_ty_param_substs: [ty::t] = [];
1446
- for ty_param_subst_var_ids.each {|var_id|
1447
- let tp_subst = ty::mk_var(fcx.ccx.tcx, var_id);
1448
- result_ty_param_substs += [tp_subst];
1449
- }
1450
- ret {substs: result_ty_param_substs, ty: result_ty};
1451
- }
1406
+ // don't.
1407
+ fn simple(fcx: @fn_ctxt, sp: span,
1408
+ expected: ty::t, actual: ty::t) {
1452
1409
1453
-
1454
- alt unifier(fcx, expected, actual) {
1455
- result::ok(()) {
1456
- ret mk_result(fcx, expected, ty_param_subst_var_ids);
1457
- }
1410
+ alt infer::mk_subty(fcx.infcx, actual, expected) {
1411
+ result::ok(()) { /* ok */ }
1458
1412
result::err(err) {
1459
1413
fcx.ccx.tcx.sess.span_err(sp,
1460
1414
" mismatched types: expected `" +
@@ -1465,7 +1419,6 @@ mod demand {
1465
1419
ty:: type_err_to_str(
1466
1420
fcx. ccx. tcx, err) +
1467
1421
") ") ;
1468
- ret mk_result( fcx, expected, ty_param_subst_var_ids) ;
1469
1422
}
1470
1423
}
1471
1424
}
@@ -1938,20 +1891,27 @@ fn universally_quantify_before_call(
1938
1891
1939
1892
fn check_pat_variant( pcx: pat_ctxt, pat: @ast:: pat, path: @ast:: path,
1940
1893
subpats: [ @ast:: pat] , expected: ty:: t) {
1894
+
1941
1895
// Typecheck the path.
1942
1896
let fcx = pcx. fcx;
1943
1897
let tcx = pcx. fcx. ccx. tcx;
1898
+
1899
+ // Lookup the enum and variant def ids:
1944
1900
let v_def = lookup_def( pcx. fcx, path. span, pat. id) ;
1945
1901
let v_def_ids = ast_util:: variant_def_ids( v_def) ;
1946
- let ctor_tpt = ty:: lookup_item_type( tcx, v_def_ids. enm) ;
1947
- instantiate_path( pcx. fcx, path, ctor_tpt, pat. span, pat. id) ;
1902
+
1903
+ // Assign the pattern the type of the *enum*, not the variant.
1904
+ let enum_tpt = ty:: lookup_item_type( tcx, v_def_ids. enm) ;
1905
+ instantiate_path( pcx. fcx, path, enum_tpt, pat. span, pat. id) ;
1948
1906
1949
1907
// Take the enum type params out of `expected`.
1950
1908
alt structure_of( pcx. fcx, pat. span, expected) {
1951
1909
ty:: ty_enum( _, expected_tps) {
1952
- let ctor_ty = fcx. node_ty( pat. id) ;
1953
- demand:: with_substs( pcx. fcx, pat. span, expected, ctor_ty,
1954
- expected_tps) ;
1910
+ // check that the type of the value being matched is a subtype
1911
+ // of the type of the pattern:
1912
+ let pat_ty = fcx. node_ty( pat. id) ;
1913
+ demand:: simple( fcx, pat. span, pat_ty, expected) ;
1914
+
1955
1915
// Get the number of arguments in this enum variant.
1956
1916
let arg_types = variant_arg_types( pcx. fcx. ccx, pat. span,
1957
1917
v_def_ids. var, expected_tps) ;
@@ -2029,12 +1989,12 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
2029
1989
if !pat_util:: pat_is_variant( tcx. def_map, pat) {
2030
1990
let vid = lookup_local( pcx. fcx, pat. span, pat. id) ;
2031
1991
let mut typ = ty:: mk_var( tcx, vid) ;
2032
- typ = demand:: simple( pcx. fcx, pat. span, expected, typ) ;
1992
+ demand:: simple( pcx. fcx, pat. span, expected, typ) ;
2033
1993
let canon_id = pcx. map. get( path_to_ident( name) ) ;
2034
1994
if canon_id != pat. id {
2035
1995
let tv_id = lookup_local( pcx. fcx, pat. span, canon_id) ;
2036
1996
let ct = ty:: mk_var( tcx, tv_id) ;
2037
- typ = demand:: simple( pcx. fcx, pat. span, ct, typ) ;
1997
+ demand:: simple( pcx. fcx, pat. span, ct, typ) ;
2038
1998
}
2039
1999
fcx. write_ty( pat. id, typ) ;
2040
2000
alt sub {
@@ -2203,12 +2163,11 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity,
2203
2163
}
2204
2164
}
2205
2165
2206
- type unifier = fn @( @fn_ctxt, span, ty:: t, ty:: t) -> ty :: t ;
2166
+ type unifier = fn @( @fn_ctxt, span, ty:: t, ty:: t) ;
2207
2167
2208
2168
fn check_expr( fcx: @fn_ctxt, expr: @ast:: expr) -> bool {
2209
- fn dummy_unify( _fcx: @fn_ctxt, _sp: span, _expected: ty:: t, actual: ty:: t)
2210
- -> ty:: t {
2211
- actual
2169
+ fn dummy_unify( _fcx: @fn_ctxt, _sp: span,
2170
+ _expected: ty:: t, _actual: ty:: t) {
2212
2171
}
2213
2172
ret check_expr_with_unifier( fcx, expr, dummy_unify,
2214
2173
ty:: mk_nil( fcx. ccx. tcx) ) ;
@@ -3139,7 +3098,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
3139
3098
}
3140
3099
if !check_block( fcx, arm. body) { arm_non_bot = true; }
3141
3100
let bty = fcx. node_ty( arm. body. node. id) ;
3142
- result_ty = demand:: simple( fcx, arm. body. span, result_ty, bty) ;
3101
+ demand:: simple( fcx, arm. body. span, result_ty, bty) ;
3143
3102
}
3144
3103
bot |= !arm_non_bot;
3145
3104
if !arm_non_bot { result_ty = ty:: mk_bot( tcx) ; }
0 commit comments