Skip to content

Commit 0fc9d39

Browse files
committed
Minimize parameter of coerce_borrowed_pointer()
1 parent 0612568 commit 0fc9d39

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/librustc_typeck/check/coercion.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
211211
ty::RawPtr(mt_b) => {
212212
return self.coerce_unsafe_ptr(a, b, mt_b.mutbl);
213213
}
214-
215-
ty::Ref(r_b, ty, mutbl) => {
216-
let mt_b = ty::TypeAndMut { ty, mutbl };
217-
return self.coerce_borrowed_pointer(a, b, r_b, mt_b);
214+
ty::Ref(r_b, _, mutbl_b) => {
215+
return self.coerce_borrowed_pointer(a, b, r_b, mutbl_b);
218216
}
219-
220217
_ => {}
221218
}
222219

@@ -255,7 +252,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
255252
a: Ty<'tcx>,
256253
b: Ty<'tcx>,
257254
r_b: ty::Region<'tcx>,
258-
mt_b: TypeAndMut<'tcx>,
255+
mutbl_b: hir::Mutability,
259256
) -> CoerceResult<'tcx> {
260257
debug!("coerce_borrowed_pointer(a={:?}, b={:?})", a, b);
261258

@@ -268,7 +265,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
268265
let (r_a, mt_a) = match a.kind {
269266
ty::Ref(r_a, ty, mutbl) => {
270267
let mt_a = ty::TypeAndMut { ty, mutbl };
271-
coerce_mutbls(mt_a.mutbl, mt_b.mutbl)?;
268+
coerce_mutbls(mt_a.mutbl, mutbl_b)?;
272269
(r_a, mt_a)
273270
}
274271
_ => return self.unify_and(a, b, identity),
@@ -364,7 +361,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
364361
r_a // [3] above
365362
} else {
366363
if r_borrow_var.is_none() {
367-
// create var lazilly, at most once
364+
// create var lazily, at most once
368365
let coercion = Coercion(span);
369366
let r = self.next_region_var(coercion);
370367
r_borrow_var = Some(r); // [4] above
@@ -375,7 +372,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
375372
r,
376373
TypeAndMut {
377374
ty: referent_ty,
378-
mutbl: mt_b.mutbl, // [1] above
375+
mutbl: mutbl_b, // [1] above
379376
},
380377
);
381378
match self.unify(derefd_ty_a, b) {
@@ -417,11 +414,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
417414
// `self.x` both have `&mut `type would be a move of
418415
// `self.x`, but we auto-coerce it to `foo(&mut *self.x)`,
419416
// which is a borrow.
420-
assert_eq!(mt_b.mutbl, hir::Mutability::Not); // can only coerce &T -> &U
417+
assert_eq!(mutbl_b, hir::Mutability::Not); // can only coerce &T -> &U
421418
return success(vec![], ty, obligations);
422419
}
423420

424-
let needs = Needs::maybe_mut_place(mt_b.mutbl);
421+
let needs = Needs::maybe_mut_place(mutbl_b);
425422
let InferOk { value: mut adjustments, obligations: o } =
426423
autoderef.adjust_steps_as_infer_ok(self, needs);
427424
obligations.extend(o);
@@ -433,7 +430,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
433430
ty::Ref(r_borrow, _, _) => r_borrow,
434431
_ => span_bug!(span, "expected a ref type, got {:?}", ty),
435432
};
436-
let mutbl = match mt_b.mutbl {
433+
let mutbl = match mutbl_b {
437434
hir::Mutability::Not => AutoBorrowMutability::Not,
438435
hir::Mutability::Mut => {
439436
AutoBorrowMutability::Mut { allow_two_phase_borrow: self.allow_two_phase }

0 commit comments

Comments
 (0)