Apply code review suggestions
This commit is contained in:
parent
7b7992fbcf
commit
a73c8b1171
3 changed files with 10 additions and 11 deletions
|
@ -216,7 +216,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
}
|
}
|
||||||
ty::Adt(pin, _)
|
ty::Adt(pin, _)
|
||||||
if self.tcx.features().pin_ergonomics
|
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);
|
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.
|
// 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>`.
|
// 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>
|
// Get the T out of Pin<T>
|
||||||
let ty = match ty.kind() {
|
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()
|
args[0].expect_ty()
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
debug!("can't reborrow {:?} as pinned", 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)
|
// Make sure the T is something we understand (just `&mut U` for now)
|
||||||
match ty.kind() {
|
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);
|
debug!("can't reborrow pin of inner type {:?}", ty);
|
||||||
None
|
Err(TypeError::Mismatch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (_, _a_ty) = can_reborrow(a).ok_or(TypeError::Mismatch)?;
|
let (_, _a_ty) = extract_pin_mut(a)?;
|
||||||
let (b_region, _b_ty) = can_reborrow(b).ok_or(TypeError::Mismatch)?;
|
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
|
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
|
||||||
// add the adjustments.
|
// 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),
|
adjustment::AutoBorrow::RawPtr(m) => ty::BorrowKind::from_mutbl(*m),
|
||||||
};
|
};
|
||||||
self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
|
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)?;
|
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.
|
/// Cast into a dyn* object.
|
||||||
DynStar,
|
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>),
|
ReborrowPin(AutoBorrow<'tcx>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue