mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 08:05:12 +00:00
Rollup merge of #71524 - ldm0:ptrparam, r=matthewjasper
Minimize parameter of coerce_borrowed_pointer() Change last parameter of `coerce_borrowed_pointer()` from `TypeAndMut` to `Mutability` (similar to `coerce_unsafe_ptr()`), since the `TypeAndMut::ty` is never used directly in this function.
This commit is contained in:
commit
e2976c1371
@ -211,12 +211,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
ty::RawPtr(mt_b) => {
|
ty::RawPtr(mt_b) => {
|
||||||
return self.coerce_unsafe_ptr(a, b, mt_b.mutbl);
|
return self.coerce_unsafe_ptr(a, b, mt_b.mutbl);
|
||||||
}
|
}
|
||||||
|
ty::Ref(r_b, _, mutbl_b) => {
|
||||||
ty::Ref(r_b, ty, mutbl) => {
|
return self.coerce_borrowed_pointer(a, b, r_b, mutbl_b);
|
||||||
let mt_b = ty::TypeAndMut { ty, mutbl };
|
|
||||||
return self.coerce_borrowed_pointer(a, b, r_b, mt_b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +252,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
a: Ty<'tcx>,
|
a: Ty<'tcx>,
|
||||||
b: Ty<'tcx>,
|
b: Ty<'tcx>,
|
||||||
r_b: ty::Region<'tcx>,
|
r_b: ty::Region<'tcx>,
|
||||||
mt_b: TypeAndMut<'tcx>,
|
mutbl_b: hir::Mutability,
|
||||||
) -> CoerceResult<'tcx> {
|
) -> CoerceResult<'tcx> {
|
||||||
debug!("coerce_borrowed_pointer(a={:?}, b={:?})", a, b);
|
debug!("coerce_borrowed_pointer(a={:?}, b={:?})", a, b);
|
||||||
|
|
||||||
@ -268,7 +265,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
let (r_a, mt_a) = match a.kind {
|
let (r_a, mt_a) = match a.kind {
|
||||||
ty::Ref(r_a, ty, mutbl) => {
|
ty::Ref(r_a, ty, mutbl) => {
|
||||||
let mt_a = ty::TypeAndMut { ty, mutbl };
|
let mt_a = ty::TypeAndMut { ty, mutbl };
|
||||||
coerce_mutbls(mt_a.mutbl, mt_b.mutbl)?;
|
coerce_mutbls(mt_a.mutbl, mutbl_b)?;
|
||||||
(r_a, mt_a)
|
(r_a, mt_a)
|
||||||
}
|
}
|
||||||
_ => return self.unify_and(a, b, identity),
|
_ => return self.unify_and(a, b, identity),
|
||||||
@ -364,7 +361,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
r_a // [3] above
|
r_a // [3] above
|
||||||
} else {
|
} else {
|
||||||
if r_borrow_var.is_none() {
|
if r_borrow_var.is_none() {
|
||||||
// create var lazilly, at most once
|
// create var lazily, at most once
|
||||||
let coercion = Coercion(span);
|
let coercion = Coercion(span);
|
||||||
let r = self.next_region_var(coercion);
|
let r = self.next_region_var(coercion);
|
||||||
r_borrow_var = Some(r); // [4] above
|
r_borrow_var = Some(r); // [4] above
|
||||||
@ -375,7 +372,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
r,
|
r,
|
||||||
TypeAndMut {
|
TypeAndMut {
|
||||||
ty: referent_ty,
|
ty: referent_ty,
|
||||||
mutbl: mt_b.mutbl, // [1] above
|
mutbl: mutbl_b, // [1] above
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
match self.unify(derefd_ty_a, b) {
|
match self.unify(derefd_ty_a, b) {
|
||||||
@ -417,11 +414,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
// `self.x` both have `&mut `type would be a move of
|
// `self.x` both have `&mut `type would be a move of
|
||||||
// `self.x`, but we auto-coerce it to `foo(&mut *self.x)`,
|
// `self.x`, but we auto-coerce it to `foo(&mut *self.x)`,
|
||||||
// which is a borrow.
|
// which is a borrow.
|
||||||
assert_eq!(mt_b.mutbl, hir::Mutability::Not); // can only coerce &T -> &U
|
assert_eq!(mutbl_b, hir::Mutability::Not); // can only coerce &T -> &U
|
||||||
return success(vec![], ty, obligations);
|
return success(vec![], ty, obligations);
|
||||||
}
|
}
|
||||||
|
|
||||||
let needs = Needs::maybe_mut_place(mt_b.mutbl);
|
let needs = Needs::maybe_mut_place(mutbl_b);
|
||||||
let InferOk { value: mut adjustments, obligations: o } =
|
let InferOk { value: mut adjustments, obligations: o } =
|
||||||
autoderef.adjust_steps_as_infer_ok(self, needs);
|
autoderef.adjust_steps_as_infer_ok(self, needs);
|
||||||
obligations.extend(o);
|
obligations.extend(o);
|
||||||
@ -433,7 +430,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
ty::Ref(r_borrow, _, _) => r_borrow,
|
ty::Ref(r_borrow, _, _) => r_borrow,
|
||||||
_ => span_bug!(span, "expected a ref type, got {:?}", ty),
|
_ => span_bug!(span, "expected a ref type, got {:?}", ty),
|
||||||
};
|
};
|
||||||
let mutbl = match mt_b.mutbl {
|
let mutbl = match mutbl_b {
|
||||||
hir::Mutability::Not => AutoBorrowMutability::Not,
|
hir::Mutability::Not => AutoBorrowMutability::Not,
|
||||||
hir::Mutability::Mut => {
|
hir::Mutability::Mut => {
|
||||||
AutoBorrowMutability::Mut { allow_two_phase_borrow: self.allow_two_phase }
|
AutoBorrowMutability::Mut { allow_two_phase_borrow: self.allow_two_phase }
|
||||||
|
Loading…
Reference in New Issue
Block a user