Apply code review suggestions

This commit is contained in:
Eric Holk 2024-09-18 15:37:50 -07:00
parent 7b7992fbcf
commit a73c8b1171
No known key found for this signature in database
GPG Key ID: F1A772BB658A63E1
3 changed files with 10 additions and 11 deletions

View File

@ -216,7 +216,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
}
ty::Adt(pin, _)
if self.tcx.features().pin_ergonomics
&& pin.did() == self.tcx.lang_items().pin_type().unwrap() =>
&& self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) =>
{
return self.coerce_pin(a, b);
}
@ -796,29 +796,29 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// Then we will build a ReborrowPin adjustment and return that as an InferOk.
// Right now we can only reborrow if this is a `Pin<&mut T>`.
let can_reborrow = |ty: Ty<'tcx>| {
let extract_pin_mut = |ty: Ty<'tcx>| {
// Get the T out of Pin<T>
let ty = match ty.kind() {
ty::Adt(pin, args) if pin.did() == self.tcx.lang_items().pin_type().unwrap() => {
ty::Adt(pin, args) if self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) => {
args[0].expect_ty()
}
_ => {
debug!("can't reborrow {:?} as pinned", ty);
return None;
return Err(TypeError::Mismatch);
}
};
// Make sure the T is something we understand (just `&mut U` for now)
match ty.kind() {
ty::Ref(region, ty, ty::Mutability::Mut) => Some((*region, *ty)),
ty::Ref(region, ty, ty::Mutability::Mut) => Ok((*region, *ty)),
_ => {
debug!("can't reborrow pin of inner type {:?}", ty);
None
Err(TypeError::Mismatch)
}
}
};
let (_, _a_ty) = can_reborrow(a).ok_or(TypeError::Mismatch)?;
let (b_region, _b_ty) = can_reborrow(b).ok_or(TypeError::Mismatch)?;
let (_, _a_ty) = extract_pin_mut(a)?;
let (b_region, _b_ty) = extract_pin_mut(b)?;
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
// add the adjustments.

View File

@ -791,8 +791,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
adjustment::AutoBorrow::RawPtr(m) => ty::BorrowKind::from_mutbl(*m),
};
self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
self.walk_autoref(expr, &place_with_id, autoref);
}
}
place_with_id = self.cat_expr_adjusted(expr, place_with_id, adjustment)?;

View File

@ -105,7 +105,8 @@ pub enum Adjust<'tcx> {
/// Cast into a dyn* object.
DynStar,
/// Take a Pin<Ptr> and call either as_mut() or as_ref() to get a Pin<&mut T> or Pin<&T>.
/// Take a `Pin<Ptr>` and call either `as_mut()` or `as_ref()` to get a `Pin<&mut T>` or
/// `Pin<&T>`.
ReborrowPin(AutoBorrow<'tcx>),
}