Skip to content

Commit 2ab69ae

Browse files
committed
typeck/pat.rs: extract new_ref_ty.
1 parent 97986b5 commit 2ab69ae

File tree

1 file changed

+9
-6
lines changed
  • src/librustc_typeck/check

1 file changed

+9
-6
lines changed

src/librustc_typeck/check/pat.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
426426
// If the binding is like `ref x | ref const x | ref mut x`
427427
// then `x` is assigned a value of type `&M T` where M is the
428428
// mutability and T is the expected type.
429-
let region_var = self.next_region_var(infer::PatternRegion(pat.span));
430-
let mt = ty::TypeAndMut { ty: expected, mutbl };
431-
let region_ty = self.tcx.mk_ref(region_var, mt);
429+
let region_ty = self.new_ref_ty(pat.span, mutbl, expected);
432430

433431
// `x` is assigned a value of type `&M T`, hence `&M T <: typeof(x)`
434432
// is required. However, we use equality, which is stronger.
@@ -971,9 +969,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
971969
span: inner.span,
972970
}
973971
);
974-
let mt = ty::TypeAndMut { ty: inner_ty, mutbl };
975-
let region = self.next_region_var(infer::PatternRegion(pat.span));
976-
let rptr_ty = tcx.mk_ref(region, mt);
972+
let rptr_ty = self.new_ref_ty(pat.span, mutbl, inner_ty);
977973
debug!("check_pat_ref: demanding {:?} = {:?}", expected, rptr_ty);
978974
let err = self.demand_eqtype_diag(pat.span, expected, rptr_ty);
979975

@@ -995,6 +991,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
995991
}
996992
}
997993

994+
/// Create a reference type with a fresh region variable.
995+
fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> {
996+
let region = self.next_region_var(infer::PatternRegion(span));
997+
let mt = ty::TypeAndMut { ty, mutbl };
998+
self.tcx.mk_ref(region, mt)
999+
}
1000+
9981001
fn check_pat_slice(
9991002
&self,
10001003
span: Span,

0 commit comments

Comments
 (0)