@@ -1055,65 +1055,72 @@ mod writeback {
1055
1055
}
1056
1056
write:: ty( fcx. ccx. tcx, id, tup( new_substs_opt, new_ty) ) ;
1057
1057
}
1058
- fn visit_stmt_pre( @fn_ctxt fcx, & @ast:: stmt s) {
1059
- resolve_type_vars_for_node( fcx, s. span, ty:: stmt_node_id( s) ) ;
1058
+
1059
+ type wb_ctxt = rec( @fn_ctxt fcx,
1060
+ // A flag to ignore contained items and lambdas
1061
+ mutable bool ignore) ;
1062
+
1063
+ fn visit_stmt_pre( @wb_ctxt wbcx, & @ast:: stmt s) {
1064
+ resolve_type_vars_for_node( wbcx. fcx, s. span, ty:: stmt_node_id( s) ) ;
1060
1065
}
1061
- fn visit_expr_pre( @fn_ctxt fcx , & @ast:: expr e) {
1062
- resolve_type_vars_for_node( fcx, e. span, e. id) ;
1066
+ fn visit_expr_pre( @wb_ctxt wbcx , & @ast:: expr e) {
1067
+ resolve_type_vars_for_node( wbcx . fcx, e. span, e. id) ;
1063
1068
}
1064
- fn visit_block_pre( @fn_ctxt fcx , & ast:: block b) {
1065
- resolve_type_vars_for_node( fcx, b. span, b. node. id) ;
1069
+ fn visit_block_pre( @wb_ctxt wbcx , & ast:: block b) {
1070
+ resolve_type_vars_for_node( wbcx . fcx, b. span, b. node. id) ;
1066
1071
}
1067
- fn visit_pat_pre( @fn_ctxt fcx , & @ast:: pat p) {
1068
- resolve_type_vars_for_node( fcx, p. span, p. id) ;
1072
+ fn visit_pat_pre( @wb_ctxt wbcx , & @ast:: pat p) {
1073
+ resolve_type_vars_for_node( wbcx . fcx, p. span, p. id) ;
1069
1074
}
1070
- fn visit_local_pre( @fn_ctxt fcx , & @ast:: local l) {
1071
- auto var_id = lookup_local( fcx, l. span, l. node. id) ;
1075
+ fn visit_local_pre( @wb_ctxt wbcx , & @ast:: local l) {
1076
+ auto var_id = lookup_local( wbcx . fcx, l. span, l. node. id) ;
1072
1077
auto fix_rslt =
1073
- ty:: unify:: resolve_type_var( fcx. ccx. tcx, fcx. var_bindings,
1078
+ ty:: unify:: resolve_type_var( wbcx. fcx. ccx. tcx,
1079
+ wbcx. fcx. var_bindings,
1074
1080
var_id) ;
1075
1081
alt ( fix_rslt) {
1076
1082
case ( fix_ok( ?lty) ) {
1077
- write:: ty_only( fcx. ccx. tcx, l. node. id, lty) ;
1083
+ write:: ty_only( wbcx . fcx. ccx. tcx, l. node. id, lty) ;
1078
1084
}
1079
1085
case ( fix_err( _) ) {
1080
- fcx. ccx. tcx. sess. span_fatal( l. span,
1081
- "cannot determine a type \
1082
- for this local variable") ;
1086
+ wbcx . fcx. ccx. tcx. sess. span_fatal( l. span,
1087
+ "cannot determine a type \
1088
+ for this local variable") ;
1083
1089
}
1084
1090
}
1085
1091
}
1092
+ fn visit_item_pre( @wb_ctxt wbcx, & @ast:: item item) {
1093
+ wbcx. ignore = true;
1094
+ }
1095
+ fn visit_item_post( @wb_ctxt wbcx, & @ast:: item item) {
1096
+ wbcx. ignore = false;
1097
+ }
1098
+ fn visit_fn_pre( @wb_ctxt wbcx, & ast:: _fn f,
1099
+ & vec[ ast:: ty_param] tps, & span sp,
1100
+ & ast:: fn_ident i, ast:: node_id d) {
1101
+ wbcx. ignore = true;
1102
+ }
1103
+ fn visit_fn_post( @wb_ctxt wbcx, & ast:: _fn f,
1104
+ & vec[ ast:: ty_param] tps, & span sp,
1105
+ & ast:: fn_ident i, ast:: node_id d) {
1106
+ wbcx. ignore = false;
1107
+ }
1108
+ fn keep_going( @wb_ctxt wbcx) -> bool { ret !wbcx. ignore; }
1109
+
1086
1110
fn resolve_type_vars_in_block( & @fn_ctxt fcx, & ast:: block block) {
1087
- // A trick to ignore any contained items and lambdas.
1088
- auto ignore = @mutable false;
1089
- fn visit_item_pre( @mutable bool ignore, & @ast:: item item) {
1090
- * ignore = true;
1091
- }
1092
- fn visit_item_post( @mutable bool ignore, & @ast:: item item) {
1093
- * ignore = false;
1094
- }
1095
- fn visit_fn_pre( @mutable bool ignore, & ast:: _fn f,
1096
- & vec[ ast:: ty_param] tps, & span sp,
1097
- & ast:: fn_ident i, ast:: node_id d) {
1098
- * ignore = true;
1099
- }
1100
- fn visit_fn_post( @mutable bool ignore, & ast:: _fn f,
1101
- & vec[ ast:: ty_param] tps, & span sp,
1102
- & ast:: fn_ident i, ast:: node_id d) {
1103
- * ignore = false;
1104
- }
1105
- fn keep_going( @mutable bool ignore) -> bool { ret !* ignore; }
1111
+ auto wbcx = @rec( fcx = fcx,
1112
+ mutable ignore = false) ;
1106
1113
auto visit =
1107
- rec( keep_going=bind keep_going( ignore ) ,
1108
- visit_item_pre=bind visit_item_pre( ignore , _) ,
1109
- visit_item_post=bind visit_item_post( ignore , _) ,
1110
- visit_fn_pre=bind visit_fn_pre( ignore , _, _, _, _, _) ,
1111
- visit_fn_post=bind visit_fn_post( ignore , _, _, _, _, _) ,
1112
- visit_stmt_pre=bind visit_stmt_pre( fcx , _) ,
1113
- visit_expr_pre=bind visit_expr_pre( fcx , _) ,
1114
- visit_block_pre=bind visit_block_pre( fcx , _) ,
1115
- visit_pat_pre=bind visit_pat_pre( fcx , _) ,
1116
- visit_local_pre=bind visit_local_pre( fcx , _)
1114
+ rec( keep_going=bind keep_going( wbcx ) ,
1115
+ visit_item_pre=bind visit_item_pre( wbcx , _) ,
1116
+ visit_item_post=bind visit_item_post( wbcx , _) ,
1117
+ visit_fn_pre=bind visit_fn_pre( wbcx , _, _, _, _, _) ,
1118
+ visit_fn_post=bind visit_fn_post( wbcx , _, _, _, _, _) ,
1119
+ visit_stmt_pre=bind visit_stmt_pre( wbcx , _) ,
1120
+ visit_expr_pre=bind visit_expr_pre( wbcx , _) ,
1121
+ visit_block_pre=bind visit_block_pre( wbcx , _) ,
1122
+ visit_pat_pre=bind visit_pat_pre( wbcx , _) ,
1123
+ visit_local_pre=bind visit_local_pre( wbcx , _)
1117
1124
with walk:: default_visitor( ) ) ;
1118
1125
walk:: walk_block( visit, block) ;
1119
1126
}
0 commit comments