Skip to content

Commit 5a7e1cb

Browse files
committed
typeck/pat.rs: dedup in check_pat_box.
1 parent 4f75327 commit 5a7e1cb

File tree

1 file changed

+12
-13
lines changed
  • src/librustc_typeck/check

1 file changed

+12
-13
lines changed

src/librustc_typeck/check/pat.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -952,22 +952,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
952952
discrim_span: Option<Span>,
953953
) -> Ty<'tcx> {
954954
let tcx = self.tcx;
955-
let inner_ty = self.next_ty_var(TypeVariableOrigin {
956-
kind: TypeVariableOriginKind::TypeInference,
957-
span: inner.span,
958-
});
959-
let uniq_ty = tcx.mk_box(inner_ty);
960-
961-
if self.check_dereferencable(span, expected, &inner) {
955+
let (box_ty, inner_ty) = if self.check_dereferencable(span, expected, &inner) {
962956
// Here, `demand::subtype` is good enough, but I don't
963957
// think any errors can be introduced by using `demand::eqtype`.
964-
self.demand_eqtype_pat(span, expected, uniq_ty, discrim_span);
965-
self.check_pat(&inner, inner_ty, def_bm, discrim_span);
966-
uniq_ty
958+
let inner_ty = self.next_ty_var(TypeVariableOrigin {
959+
kind: TypeVariableOriginKind::TypeInference,
960+
span: inner.span,
961+
});
962+
let box_ty = tcx.mk_box(inner_ty);
963+
self.demand_eqtype_pat(span, expected, box_ty, discrim_span);
964+
(box_ty, inner_ty)
967965
} else {
968-
self.check_pat(&inner, tcx.types.err, def_bm, discrim_span);
969-
tcx.types.err
970-
}
966+
(tcx.types.err, tcx.types.err)
967+
};
968+
self.check_pat(&inner, inner_ty, def_bm, discrim_span);
969+
box_ty
971970
}
972971

973972
fn check_pat_ref(

0 commit comments

Comments
 (0)