Skip to content

Commit bd66148

Browse files
committed
Move write_ty to the bottom of check_pat
1 parent 1749fda commit bd66148

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3232

3333
debug!("check_pat(pat={:?},expected={:?})", pat, expected);
3434

35-
match pat.node {
35+
let ty = match pat.node {
3636
PatKind::Wild => {
37-
self.write_ty(pat.id, expected);
37+
expected
3838
}
3939
PatKind::Lit(ref lt) => {
4040
let ty = self.check_expr(&lt);
@@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6767
//
6868
// that's equivalent to there existing a LUB.
6969
self.demand_suptype(pat.span, expected, pat_ty);
70-
self.write_ty(pat.id, pat_ty);
70+
pat_ty
7171
}
7272
PatKind::Range(ref begin, ref end) => {
7373
let lhs_ty = self.check_expr(begin);
@@ -103,7 +103,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
103103
// subtyping doesn't matter here, as the value is some kind of scalar
104104
self.demand_eqtype(pat.span, expected, lhs_ty);
105105
self.demand_eqtype(pat.span, expected, rhs_ty);
106-
self.write_ty(pat.id, common_type);
106+
common_type
107107
}
108108
PatKind::Binding(bm, _, ref sub) => {
109109
let typ = self.local_ty(pat.span, pat.id);
@@ -147,20 +147,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
147147
self.check_pat(&p, expected);
148148
}
149149

150-
self.write_ty(pat.id, typ);
150+
typ
151151
}
152152
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)
155154
}
156155
PatKind::Path(ref opt_qself, ref path) => {
157156
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)
160158
}
161159
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)
164161
}
165162
PatKind::Tuple(ref elements, ddpos) => {
166163
let mut expected_len = elements.len();
@@ -179,7 +176,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
179176
for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
180177
self.check_pat(elem, &element_tys[i]);
181178
}
182-
self.write_ty(pat.id, pat_ty);
179+
pat_ty
183180
}
184181
PatKind::Box(ref inner) => {
185182
let inner_ty = self.next_ty_var();
@@ -191,10 +188,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
191188
// `demand::eqtype`.
192189
self.demand_eqtype(pat.span, expected, uniq_ty);
193190
self.check_pat(&inner, inner_ty);
194-
self.write_ty(pat.id, uniq_ty);
191+
uniq_ty
195192
} else {
196193
self.check_pat(&inner, tcx.types.err);
197-
self.write_error(pat.id);
194+
tcx.types.err
198195
}
199196
}
200197
PatKind::Ref(ref inner, mutbl) => {
@@ -223,10 +220,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
223220
};
224221

225222
self.check_pat(&inner, inner_ty);
226-
self.write_ty(pat.id, rptr_ty);
223+
rptr_ty
227224
} else {
228225
self.check_pat(&inner, tcx.types.err);
229-
self.write_error(pat.id);
226+
tcx.types.err
230227
}
231228
}
232229
PatKind::Vec(ref before, ref slice, ref after) => {
@@ -287,9 +284,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
287284
for elt in after {
288285
self.check_pat(&elt, inner_ty);
289286
}
290-
self.write_ty(pat.id, expected_ty);
287+
expected_ty
291288
}
292-
}
289+
};
290+
291+
self.write_ty(pat.id, ty);
293292

294293
// (*) In most of the cases above (literals and constants being
295294
// the exception), we relate types using strict equality, evewn
@@ -494,7 +493,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
494493
for field in fields {
495494
self.check_pat(&field.node.pat, self.tcx.types.err);
496495
}
497-
return tcx.types.err;
496+
return self.tcx.types.err;
498497
};
499498

500499
// Type check the path.

0 commit comments

Comments
 (0)