Skip to content

Commit

Permalink
Move write_ty to the bottom of check_pat
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Sep 5, 2016
1 parent 1749fda commit bd66148
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -32,9 +32,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

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

match pat.node {
let ty = match pat.node {
PatKind::Wild => {
self.write_ty(pat.id, expected);
expected
}
PatKind::Lit(ref lt) => {
let ty = self.check_expr(&lt);
Expand Down Expand Up @@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
//
// that's equivalent to there existing a LUB.
self.demand_suptype(pat.span, expected, pat_ty);
self.write_ty(pat.id, pat_ty);
pat_ty
}
PatKind::Range(ref begin, ref end) => {
let lhs_ty = self.check_expr(begin);
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// subtyping doesn't matter here, as the value is some kind of scalar
self.demand_eqtype(pat.span, expected, lhs_ty);
self.demand_eqtype(pat.span, expected, rhs_ty);
self.write_ty(pat.id, common_type);
common_type
}
PatKind::Binding(bm, _, ref sub) => {
let typ = self.local_ty(pat.span, pat.id);
Expand Down Expand Up @@ -147,20 +147,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.check_pat(&p, expected);
}

self.write_ty(pat.id, typ);
typ
}
PatKind::TupleStruct(ref path, ref subpats, ddpos) => {
let pat_ty = self.check_pat_tuple_struct(pat, path, &subpats, ddpos, expected);
write_ty(pat.id, pat_ty);
self.check_pat_tuple_struct(pat, path, &subpats, ddpos, expected)
}
PatKind::Path(ref opt_qself, ref path) => {
let opt_qself_ty = opt_qself.as_ref().map(|qself| self.to_ty(&qself.ty));
let pat_ty = self.check_pat_path(pat, opt_qself_ty, path, expected);
write_ty(pat.id, pat_ty);
self.check_pat_path(pat, opt_qself_ty, path, expected)
}
PatKind::Struct(ref path, ref fields, etc) => {
let pat_ty = self.check_pat_struct(pat, path, fields, etc, expected);
write_ty(pat.id, pat_ty);
self.check_pat_struct(pat, path, fields, etc, expected)
}
PatKind::Tuple(ref elements, ddpos) => {
let mut expected_len = elements.len();
Expand All @@ -179,7 +176,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
self.check_pat(elem, &element_tys[i]);
}
self.write_ty(pat.id, pat_ty);
pat_ty
}
PatKind::Box(ref inner) => {
let inner_ty = self.next_ty_var();
Expand All @@ -191,10 +188,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// `demand::eqtype`.
self.demand_eqtype(pat.span, expected, uniq_ty);
self.check_pat(&inner, inner_ty);
self.write_ty(pat.id, uniq_ty);
uniq_ty
} else {
self.check_pat(&inner, tcx.types.err);
self.write_error(pat.id);
tcx.types.err
}
}
PatKind::Ref(ref inner, mutbl) => {
Expand Down Expand Up @@ -223,10 +220,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};

self.check_pat(&inner, inner_ty);
self.write_ty(pat.id, rptr_ty);
rptr_ty
} else {
self.check_pat(&inner, tcx.types.err);
self.write_error(pat.id);
tcx.types.err
}
}
PatKind::Vec(ref before, ref slice, ref after) => {
Expand Down Expand Up @@ -287,9 +284,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
for elt in after {
self.check_pat(&elt, inner_ty);
}
self.write_ty(pat.id, expected_ty);
expected_ty
}
}
};

self.write_ty(pat.id, ty);

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

// Type check the path.
Expand Down

0 comments on commit bd66148

Please sign in to comment.