@@ -32,9 +32,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32
32
33
33
debug ! ( "check_pat(pat={:?},expected={:?})" , pat, expected) ;
34
34
35
- match pat. node {
35
+ let ty = match pat. node {
36
36
PatKind :: Wild => {
37
- self . write_ty ( pat . id , expected) ;
37
+ expected
38
38
}
39
39
PatKind :: Lit ( ref lt) => {
40
40
let ty = self . check_expr ( & lt) ;
@@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
67
67
//
68
68
// that's equivalent to there existing a LUB.
69
69
self . demand_suptype ( pat. span , expected, pat_ty) ;
70
- self . write_ty ( pat . id , pat_ty) ;
70
+ pat_ty
71
71
}
72
72
PatKind :: Range ( ref begin, ref end) => {
73
73
let lhs_ty = self . check_expr ( begin) ;
@@ -103,7 +103,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
103
103
// subtyping doesn't matter here, as the value is some kind of scalar
104
104
self . demand_eqtype ( pat. span , expected, lhs_ty) ;
105
105
self . demand_eqtype ( pat. span , expected, rhs_ty) ;
106
- self . write_ty ( pat . id , common_type) ;
106
+ common_type
107
107
}
108
108
PatKind :: Binding ( bm, _, ref sub) => {
109
109
let typ = self . local_ty ( pat. span , pat. id ) ;
@@ -147,20 +147,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
147
147
self . check_pat ( & p, expected) ;
148
148
}
149
149
150
- self . write_ty ( pat . id , typ) ;
150
+ typ
151
151
}
152
152
PatKind :: TupleStruct ( ref path, ref subpats, ddpos) => {
153
- let pat_ty = self . check_pat_tuple_struct ( pat, path, & subpats, ddpos, expected) ;
154
- write_ty ( pat. id , pat_ty) ;
153
+ self . check_pat_tuple_struct ( pat, path, & subpats, ddpos, expected)
155
154
}
156
155
PatKind :: Path ( ref opt_qself, ref path) => {
157
156
let opt_qself_ty = opt_qself. as_ref ( ) . map ( |qself| self . to_ty ( & qself. ty ) ) ;
158
- let pat_ty = self . check_pat_path ( pat, opt_qself_ty, path, expected) ;
159
- write_ty ( pat. id , pat_ty) ;
157
+ self . check_pat_path ( pat, opt_qself_ty, path, expected)
160
158
}
161
159
PatKind :: Struct ( ref path, ref fields, etc) => {
162
- let pat_ty = self . check_pat_struct ( pat, path, fields, etc, expected) ;
163
- write_ty ( pat. id , pat_ty) ;
160
+ self . check_pat_struct ( pat, path, fields, etc, expected)
164
161
}
165
162
PatKind :: Tuple ( ref elements, ddpos) => {
166
163
let mut expected_len = elements. len ( ) ;
@@ -179,7 +176,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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
}
182
- self . write_ty ( pat . id , pat_ty) ;
179
+ pat_ty
183
180
}
184
181
PatKind :: Box ( ref inner) => {
185
182
let inner_ty = self . next_ty_var ( ) ;
@@ -191,10 +188,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
191
188
// `demand::eqtype`.
192
189
self . demand_eqtype ( pat. span , expected, uniq_ty) ;
193
190
self . check_pat ( & inner, inner_ty) ;
194
- self . write_ty ( pat . id , uniq_ty) ;
191
+ uniq_ty
195
192
} else {
196
193
self . check_pat ( & inner, tcx. types . err ) ;
197
- self . write_error ( pat . id ) ;
194
+ tcx . types . err
198
195
}
199
196
}
200
197
PatKind :: Ref ( ref inner, mutbl) => {
@@ -223,10 +220,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
223
220
} ;
224
221
225
222
self . check_pat ( & inner, inner_ty) ;
226
- self . write_ty ( pat . id , rptr_ty) ;
223
+ rptr_ty
227
224
} else {
228
225
self . check_pat ( & inner, tcx. types . err ) ;
229
- self . write_error ( pat . id ) ;
226
+ tcx . types . err
230
227
}
231
228
}
232
229
PatKind :: Vec ( ref before, ref slice, ref after) => {
@@ -287,9 +284,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
287
284
for elt in after {
288
285
self . check_pat ( & elt, inner_ty) ;
289
286
}
290
- self . write_ty ( pat . id , expected_ty) ;
287
+ expected_ty
291
288
}
292
- }
289
+ } ;
290
+
291
+ self . write_ty ( pat. id , ty) ;
293
292
294
293
// (*) In most of the cases above (literals and constants being
295
294
// the exception), we relate types using strict equality, evewn
@@ -494,7 +493,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
494
493
for field in fields {
495
494
self . check_pat ( & field. node . pat , self . tcx . types . err ) ;
496
495
}
497
- return tcx. types . err ;
496
+ return self . tcx . types . err ;
498
497
} ;
499
498
500
499
// Type check the path.
0 commit comments