mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Apply code review suggestions
This commit is contained in:
parent
7b7992fbcf
commit
a73c8b1171
@ -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.
|
||||
|
@ -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)?;
|
||||
|
@ -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>),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user