@@ -54,8 +54,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
54
54
}
55
55
}
56
56
57
- self . write_ty ( pat. id , pat_ty) ;
58
-
59
57
// somewhat surprising: in this case, the subtyping
60
58
// relation goes the opposite way as the other
61
59
// cases. Actually what we really want is not a subtyping
@@ -69,6 +67,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
69
67
//
70
68
// that's equivalent to there existing a LUB.
71
69
self . demand_suptype ( pat. span , expected, pat_ty) ;
70
+ self . write_ty ( pat. id , pat_ty) ;
72
71
}
73
72
PatKind :: Range ( ref begin, ref end) => {
74
73
let lhs_ty = self . check_expr ( begin) ;
@@ -101,11 +100,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
101
100
// it to type the entire expression.
102
101
let common_type = self . resolve_type_vars_if_possible ( & lhs_ty) ;
103
102
104
- self . write_ty ( pat. id , common_type) ;
105
-
106
103
// subtyping doesn't matter here, as the value is some kind of scalar
107
104
self . demand_eqtype ( pat. span , expected, lhs_ty) ;
108
105
self . demand_eqtype ( pat. span , expected, rhs_ty) ;
106
+ self . write_ty ( pat. id , common_type) ;
109
107
}
110
108
PatKind :: Binding ( bm, _, ref sub) => {
111
109
let typ = self . local_ty ( pat. span , pat. id ) ;
@@ -132,8 +130,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132
130
}
133
131
}
134
132
135
- self . write_ty ( pat. id , typ) ;
136
-
137
133
// if there are multiple arms, make sure they all agree on
138
134
// what the type of the binding `x` ought to be
139
135
match tcx. expect_def ( pat. id ) {
@@ -150,6 +146,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
150
146
if let Some ( ref p) = * sub {
151
147
self . check_pat ( & p, expected) ;
152
148
}
149
+
150
+ self . write_ty ( pat. id , typ) ;
153
151
}
154
152
PatKind :: TupleStruct ( ref path, ref subpats, ddpos) => {
155
153
self . check_pat_tuple_struct ( pat, path, & subpats, ddpos, expected) ;
@@ -174,11 +172,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
174
172
175
173
let element_tys: Vec < _ > = ( 0 .. max_len) . map ( |_| self . next_ty_var ( ) ) . collect ( ) ;
176
174
let pat_ty = tcx. mk_tup ( element_tys. clone ( ) ) ;
177
- self . write_ty ( pat. id , pat_ty) ;
178
175
self . demand_eqtype ( pat. span , expected, pat_ty) ;
179
176
for ( i, elem) in elements. iter ( ) . enumerate_and_adjust ( max_len, ddpos) {
180
177
self . check_pat ( elem, & element_tys[ i] ) ;
181
178
}
179
+ self . write_ty ( pat. id , pat_ty) ;
182
180
}
183
181
PatKind :: Box ( ref inner) => {
184
182
let inner_ty = self . next_ty_var ( ) ;
@@ -189,11 +187,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
189
187
// think any errors can be introduced by using
190
188
// `demand::eqtype`.
191
189
self . demand_eqtype ( pat. span , expected, uniq_ty) ;
192
- self . write_ty ( pat. id , uniq_ty) ;
193
190
self . check_pat ( & inner, inner_ty) ;
191
+ self . write_ty ( pat. id , uniq_ty) ;
194
192
} else {
195
- self . write_error ( pat. id ) ;
196
193
self . check_pat ( & inner, tcx. types . err ) ;
194
+ self . write_error ( pat. id ) ;
197
195
}
198
196
}
199
197
PatKind :: Ref ( ref inner, mutbl) => {
@@ -221,11 +219,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
221
219
}
222
220
} ;
223
221
224
- self . write_ty ( pat. id , rptr_ty) ;
225
222
self . check_pat ( & inner, inner_ty) ;
223
+ self . write_ty ( pat. id , rptr_ty) ;
226
224
} else {
227
- self . write_error ( pat. id ) ;
228
225
self . check_pat ( & inner, tcx. types . err ) ;
226
+ self . write_error ( pat. id ) ;
229
227
}
230
228
}
231
229
PatKind :: Vec ( ref before, ref slice, ref after) => {
@@ -277,8 +275,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
277
275
}
278
276
} ;
279
277
280
- self . write_ty ( pat. id , expected_ty) ;
281
-
282
278
for elt in before {
283
279
self . check_pat ( & elt, inner_ty) ;
284
280
}
@@ -288,6 +284,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
288
284
for elt in after {
289
285
self . check_pat ( & elt, inner_ty) ;
290
286
}
287
+ self . write_ty ( pat. id , expected_ty) ;
291
288
}
292
289
}
293
290
0 commit comments