@@ -890,7 +890,6 @@ mod unify {
890
890
}
891
891
}
892
892
893
- tag autoderef_kind { AUTODEREF_OK ; NO_AUTODEREF ; AUTODEREF_BLOCK_COERCE ; }
894
893
895
894
// FIXME This is almost a duplicate of ty::type_autoderef, with structure_of
896
895
// instead of ty::struct.
@@ -929,27 +928,8 @@ fn do_autoderef(fcx: &@fn_ctxt, sp: &span, t: &ty::t) -> ty::t {
929
928
fail;
930
929
}
931
930
932
- fn add_boxes ( ccx : & @crate_ctxt , n : uint , t : & ty:: t ) -> ty:: t {
933
- let t1 = t;
934
- while n != 0 u { t1 = ty:: mk_imm_box ( ccx. tcx , t1) ; n -= 1 u; }
935
- ret t1;
936
- }
937
-
938
- fn count_boxes ( fcx : & @fn_ctxt , sp : & span , t : & ty:: t ) -> uint {
939
- let n = 0 u;
940
- let t1 = t;
941
- while true {
942
- alt structure_of ( fcx, sp, t1) {
943
- ty:: ty_box ( inner) { n += 1 u; t1 = inner. ty ; }
944
- _ { ret n; }
945
- }
946
- }
947
- fail;
948
- }
949
-
950
931
fn do_fn_block_coerce ( fcx : & @fn_ctxt , sp : & span , actual : & ty:: t ,
951
932
expected : & ty:: t ) -> ty:: t {
952
-
953
933
// fns can be silently coerced to blocks when being used as
954
934
// function call or bind arguments, but not the reverse.
955
935
// If our actual type is a fn and our expected type is a block,
@@ -986,27 +966,26 @@ type ty_param_substs_and_ty = {substs: [ty::t], ty: ty::t};
986
966
mod demand {
987
967
fn simple ( fcx : & @fn_ctxt , sp : & span , expected : & ty:: t , actual : & ty:: t ) ->
988
968
ty:: t {
989
- ret full ( fcx, sp, expected, actual, ~[ ] , NO_AUTODEREF ) . ty ;
969
+ full ( fcx, sp, expected, actual, ~[ ] , false ) . ty
970
+ }
971
+ fn block_coerce ( fcx : & @fn_ctxt , sp : & span ,
972
+ expected : & ty:: t , actual : & ty:: t ) -> ty:: t {
973
+ full ( fcx, sp, expected, actual, ~[ ] , true ) . ty
990
974
}
991
- fn autoderef ( fcx : & @fn_ctxt , sp : & span , expected : & ty:: t , actual : & ty:: t ,
992
- adk : autoderef_kind ) -> ty:: t {
993
- ret full ( fcx, sp, expected, actual, ~[ ] , adk) . ty ;
975
+
976
+ fn with_substs ( fcx : & @fn_ctxt , sp : & span , expected : & ty:: t ,
977
+ actual : & ty:: t , ty_param_substs_0 : & [ ty:: t ] ) ->
978
+ ty_param_substs_and_ty {
979
+ full ( fcx, sp, expected, actual, ty_param_substs_0, false )
994
980
}
995
981
996
982
// Requires that the two types unify, and prints an error message if they
997
983
// don't. Returns the unified type and the type parameter substitutions.
998
- fn full ( fcx : & @fn_ctxt , sp : & span , expected : & ty:: t , actual : & ty:: t ,
999
- ty_param_substs_0 : & [ ty:: t ] , adk : autoderef_kind ) ->
984
+ fn full ( fcx : & @fn_ctxt , sp : & span , expected : ty:: t , actual : ty:: t ,
985
+ ty_param_substs_0 : & [ ty:: t ] , do_block_coerece : bool ) ->
1000
986
ty_param_substs_and_ty {
1001
- let expected_1 = expected;
1002
- let actual_1 = actual;
1003
- let implicit_boxes = 0 u;
1004
- if adk == AUTODEREF_OK {
1005
- expected_1 = do_autoderef ( fcx, sp, expected_1) ;
1006
- actual_1 = do_autoderef ( fcx, sp, actual_1) ;
1007
- implicit_boxes = count_boxes ( fcx, sp, actual) ;
1008
- } else if ( adk == AUTODEREF_BLOCK_COERCE ) {
1009
- actual_1 = do_fn_block_coerce ( fcx, sp, actual, expected) ;
987
+ if do_block_coerece {
988
+ actual = do_fn_block_coerce ( fcx, sp, actual, expected) ;
1010
989
}
1011
990
1012
991
let ty_param_substs: [ mutable ty:: t ] = ~[ mutable] ;
@@ -1021,33 +1000,31 @@ mod demand {
1021
1000
}
1022
1001
1023
1002
fn mk_result ( fcx : & @fn_ctxt , result_ty : & ty:: t ,
1024
- ty_param_subst_var_ids : & [ int ] , implicit_boxes : uint ) ->
1003
+ ty_param_subst_var_ids : & [ int ] ) ->
1025
1004
ty_param_substs_and_ty {
1026
1005
let result_ty_param_substs: [ ty:: t ] = ~[ ] ;
1027
1006
for var_id: int in ty_param_subst_var_ids {
1028
1007
let tp_subst = ty:: mk_var ( fcx. ccx . tcx , var_id) ;
1029
1008
result_ty_param_substs += ~[ tp_subst] ;
1030
1009
}
1031
- ret { substs : result_ty_param_substs,
1032
- ty : add_boxes ( fcx. ccx , implicit_boxes, result_ty) } ;
1010
+ ret { substs : result_ty_param_substs, ty : result_ty} ;
1033
1011
}
1034
1012
1035
1013
1036
- alt unify:: unify ( fcx, expected_1 , actual_1 ) {
1014
+ alt unify:: unify ( fcx, expected , actual ) {
1037
1015
ures_ok ( t) {
1038
- ret mk_result ( fcx, t, ty_param_subst_var_ids, implicit_boxes ) ;
1016
+ ret mk_result ( fcx, t, ty_param_subst_var_ids) ;
1039
1017
}
1040
1018
ures_err ( err) {
1041
- let e_err = resolve_type_vars_if_possible ( fcx, expected_1 ) ;
1042
- let a_err = resolve_type_vars_if_possible ( fcx, actual_1 ) ;
1019
+ let e_err = resolve_type_vars_if_possible ( fcx, expected ) ;
1020
+ let a_err = resolve_type_vars_if_possible ( fcx, actual ) ;
1043
1021
fcx. ccx . tcx . sess . span_err ( sp,
1044
1022
"mismatched types: expected " +
1045
1023
ty_to_str ( fcx. ccx . tcx , e_err) +
1046
1024
" but found " +
1047
1025
ty_to_str ( fcx. ccx . tcx , a_err) + " ("
1048
1026
+ ty:: type_err_to_str ( err) + ")" ) ;
1049
- ret mk_result( fcx, expected_1, ty_param_subst_var_ids,
1050
- implicit_boxes) ;
1027
+ ret mk_result( fcx, expected, ty_param_subst_var_ids) ;
1051
1028
}
1052
1029
}
1053
1030
}
@@ -1379,8 +1356,8 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast::pat_id_map, pat: &@ast::pat,
1379
1356
path_tpot) ;
1380
1357
1381
1358
let path_tpt =
1382
- demand:: full ( fcx, pat. span , expected, ctor_ty, expected_tps ,
1383
- NO_AUTODEREF ) ;
1359
+ demand:: with_substs ( fcx, pat. span , expected, ctor_ty,
1360
+ expected_tps ) ;
1384
1361
path_tpot =
1385
1362
{ substs: some[ [ ty:: t] ] ( path_tpt. substs ) , ty: path_tpt. ty } ;
1386
1363
@@ -1604,13 +1581,11 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
1604
1581
}
1605
1582
1606
1583
// Check the arguments.
1607
- let unifier =
1608
- bind demand:: autoderef ( _, _, _, _, AUTODEREF_BLOCK_COERCE ) ;
1609
1584
let i = 0 u;
1610
1585
for a_opt: option:: t[ @ast:: expr] in args {
1611
1586
alt a_opt {
1612
1587
some( a) {
1613
- bot |= check_expr_with_unifier ( fcx, a, unifier ,
1588
+ bot |= check_expr_with_unifier ( fcx, a, demand :: block_coerce ,
1614
1589
arg_tys. ( i) . ty ) ;
1615
1590
}
1616
1591
none. { }
@@ -1776,12 +1751,10 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
1776
1751
let lhs_t = next_ty_var ( fcx) ;
1777
1752
bot = check_expr_with ( fcx, lhs, lhs_t) ;
1778
1753
1779
- let unifier = bind demand:: autoderef ( _, _, _, _, AUTODEREF_OK ) ;
1780
- let rhs_bot = check_expr_with_unifier ( fcx, rhs, unifier, lhs_t) ;
1754
+ let rhs_bot = check_expr_with ( fcx, rhs, lhs_t) ;
1781
1755
if !ast:: lazy_binop ( binop) { bot |= rhs_bot; }
1782
1756
1783
- let deref_t = do_autoderef ( fcx, expr. span , lhs_t) ;
1784
- check_binop_type_compat ( fcx, expr. span , deref_t, binop) ;
1757
+ check_binop_type_compat ( fcx, expr. span , lhs_t, binop) ;
1785
1758
1786
1759
let t =
1787
1760
alt binop {
@@ -1791,7 +1764,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
1791
1764
ast:: ne. { ty:: mk_bool ( tcx) }
1792
1765
ast:: ge. { ty:: mk_bool ( tcx) }
1793
1766
ast:: gt. { ty:: mk_bool ( tcx) }
1794
- _ { deref_t }
1767
+ _ { lhs_t }
1795
1768
} ;
1796
1769
write:: ty_only_fixup ( fcx, id, t) ;
1797
1770
}
@@ -1838,8 +1811,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
1838
1811
}
1839
1812
}
1840
1813
ast:: neg. {
1841
- oper_t = structurally_resolved_type
1842
- ( fcx, oper. span , do_autoderef ( fcx, expr. span , oper_t) ) ;
1814
+ oper_t = structurally_resolved_type ( fcx, oper. span , oper_t) ;
1843
1815
if !( ty:: type_is_integral ( tcx, oper_t) ||
1844
1816
ty:: type_is_fp ( tcx, oper_t) ) {
1845
1817
tcx. sess . span_fatal ( expr. span , "applying unary minus to \
0 commit comments