@@ -85,6 +85,32 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
85
85
fn tcx ( & self ) -> & ' cx ty:: ctxt < ' tcx > {
86
86
self . fcx . tcx ( )
87
87
}
88
+
89
+ // Hacky hack: During type-checking, we treat *all* operators
90
+ // as potentially overloaded. But then, during writeback, if
91
+ // we observe that something like `a+b` is (known to be)
92
+ // operating on scalars, we clear the overload.
93
+ fn fix_scalar_binary_expr ( & mut self , e : & ast:: Expr ) {
94
+ if let ast:: ExprBinary ( ref op, ref lhs, ref rhs) = e. node {
95
+ let lhs_ty = self . fcx . expr_ty ( lhs. id ) ;
96
+ let lhs_ty = self . fcx . infcx ( ) . resolve_type_vars_if_possible ( & lhs_ty) ;
97
+
98
+ let rhs_ty = self . fcx . expr_ty ( rhs. id ) ;
99
+ let rhs_ty = self . fcx . infcx ( ) . resolve_type_vars_if_possible ( & rhs_ty) ;
100
+
101
+ if ty:: type_is_scalar ( lhs_ty) && ty:: type_is_scalar ( rhs_ty) {
102
+ self . fcx . inh . method_map . borrow_mut ( ) . remove ( & MethodCall :: expr ( e. id ) ) ;
103
+
104
+ // weird but true: the by-ref binops put an
105
+ // adjustment on the lhs but not the rhs; the
106
+ // adjustment for rhs is kind of baked into the
107
+ // system.
108
+ if !ast_util:: is_by_value_binop ( op. node ) {
109
+ self . fcx . inh . adjustments . borrow_mut ( ) . remove ( & lhs. id ) ;
110
+ }
111
+ }
112
+ }
113
+ }
88
114
}
89
115
90
116
///////////////////////////////////////////////////////////////////////////
@@ -114,43 +140,16 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
114
140
return ;
115
141
}
116
142
117
- // Hacky hack: During type-checking, we treat *all* operators
118
- // as potentially overloaded. But then, during writeback, if
119
- // we observe that something like `a+b` is (known to be)
120
- // operating on scalars, we clear the overload.
121
- match e. node {
122
- ast:: ExprBinary ( ref op, ref lhs, ref rhs) => {
123
- let lhs_ty = self . fcx . expr_ty ( lhs) ;
124
- let lhs_ty = self . fcx . infcx ( ) . resolve_type_vars_if_possible ( & lhs_ty) ;
125
- let rhs_ty = self . fcx . expr_ty ( rhs) ;
126
- let rhs_ty = self . fcx . infcx ( ) . resolve_type_vars_if_possible ( & rhs_ty) ;
127
- if ty:: type_is_scalar ( lhs_ty) && ty:: type_is_scalar ( rhs_ty) {
128
- self . fcx . inh . method_map . borrow_mut ( ) . remove ( & MethodCall :: expr ( e. id ) ) ;
129
-
130
- // weird but true: the by-ref binops put an
131
- // adjustment on the lhs but not the rhs; the
132
- // adjustment for rhs is kind of baked into the
133
- // system.
134
- if !ast_util:: is_by_value_binop ( op. node ) {
135
- self . fcx . inh . adjustments . borrow_mut ( ) . remove ( & lhs. id ) ;
136
- }
137
- }
138
- }
139
- _ => { }
140
- }
143
+ self . fix_scalar_binary_expr ( e) ;
141
144
142
145
self . visit_node_id ( ResolvingExpr ( e. span ) , e. id ) ;
143
146
self . visit_method_map_entry ( ResolvingExpr ( e. span ) ,
144
147
MethodCall :: expr ( e. id ) ) ;
145
148
146
- match e. node {
147
- ast:: ExprClosure ( _, ref decl, _) => {
148
- for input in & decl. inputs {
149
- let _ = self . visit_node_id ( ResolvingExpr ( e. span ) ,
150
- input. id ) ;
151
- }
149
+ if let ast:: ExprClosure ( _, ref decl, _) = e. node {
150
+ for input in & decl. inputs {
151
+ self . visit_node_id ( ResolvingExpr ( e. span ) , input. id ) ;
152
152
}
153
- _ => { }
154
153
}
155
154
156
155
visit:: walk_expr ( self , e) ;
0 commit comments