Skip to content

Commit a73c8b1

Browse files
committed
Apply code review suggestions
1 parent 7b7992f commit a73c8b1

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
216216
}
217217
ty::Adt(pin, _)
218218
if self.tcx.features().pin_ergonomics
219-
&& pin.did() == self.tcx.lang_items().pin_type().unwrap() =>
219+
&& self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) =>
220220
{
221221
return self.coerce_pin(a, b);
222222
}
@@ -796,29 +796,29 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
796796
// Then we will build a ReborrowPin adjustment and return that as an InferOk.
797797

798798
// Right now we can only reborrow if this is a `Pin<&mut T>`.
799-
let can_reborrow = |ty: Ty<'tcx>| {
799+
let extract_pin_mut = |ty: Ty<'tcx>| {
800800
// Get the T out of Pin<T>
801801
let ty = match ty.kind() {
802-
ty::Adt(pin, args) if pin.did() == self.tcx.lang_items().pin_type().unwrap() => {
802+
ty::Adt(pin, args) if self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) => {
803803
args[0].expect_ty()
804804
}
805805
_ => {
806806
debug!("can't reborrow {:?} as pinned", ty);
807-
return None;
807+
return Err(TypeError::Mismatch);
808808
}
809809
};
810810
// Make sure the T is something we understand (just `&mut U` for now)
811811
match ty.kind() {
812-
ty::Ref(region, ty, ty::Mutability::Mut) => Some((*region, *ty)),
812+
ty::Ref(region, ty, ty::Mutability::Mut) => Ok((*region, *ty)),
813813
_ => {
814814
debug!("can't reborrow pin of inner type {:?}", ty);
815-
None
815+
Err(TypeError::Mismatch)
816816
}
817817
}
818818
};
819819

820-
let (_, _a_ty) = can_reborrow(a).ok_or(TypeError::Mismatch)?;
821-
let (b_region, _b_ty) = can_reborrow(b).ok_or(TypeError::Mismatch)?;
820+
let (_, _a_ty) = extract_pin_mut(a)?;
821+
let (b_region, _b_ty) = extract_pin_mut(b)?;
822822

823823
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
824824
// add the adjustments.

Diff for: compiler/rustc_hir_typeck/src/expr_use_visitor.rs

-2
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
791791
adjustment::AutoBorrow::RawPtr(m) => ty::BorrowKind::from_mutbl(*m),
792792
};
793793
self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
794-
795-
self.walk_autoref(expr, &place_with_id, autoref);
796794
}
797795
}
798796
place_with_id = self.cat_expr_adjusted(expr, place_with_id, adjustment)?;

Diff for: compiler/rustc_middle/src/ty/adjustment.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ pub enum Adjust<'tcx> {
105105
/// Cast into a dyn* object.
106106
DynStar,
107107

108-
/// Take a Pin<Ptr> and call either as_mut() or as_ref() to get a Pin<&mut T> or Pin<&T>.
108+
/// Take a `Pin<Ptr>` and call either `as_mut()` or `as_ref()` to get a `Pin<&mut T>` or
109+
/// `Pin<&T>`.
109110
ReborrowPin(AutoBorrow<'tcx>),
110111
}
111112

0 commit comments

Comments
 (0)