From f78cbce6484b76886e5849e8f0c5372cba5223fe Mon Sep 17 00:00:00 2001 From: Frank King Date: Sun, 1 Feb 2026 10:13:36 +0800 Subject: [PATCH] refactor: remove `Adjust::ReborrowPin` --- .../rustc_hir_typeck/src/expr_use_visitor.rs | 13 +--- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 -- .../rustc_hir_typeck/src/method/confirm.rs | 11 +++- compiler/rustc_lint/src/autorefs.rs | 1 - compiler/rustc_middle/src/ty/adjustment.rs | 4 -- compiler/rustc_mir_build/src/thir/cx/expr.rs | 62 ------------------- 6 files changed, 9 insertions(+), 86 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index b6dfda33142c5..9587b774c4ff2 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -751,16 +751,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx adjustment::Adjust::Borrow(ref autoref) => { self.walk_autoref(expr, &place_with_id, autoref); } - - adjustment::Adjust::ReborrowPin(mutbl) => { - // Reborrowing a Pin is like a combinations of a deref and a borrow, so we do - // both. - let bk = match mutbl { - ty::Mutability::Not => ty::BorrowKind::Immutable, - ty::Mutability::Mut => ty::BorrowKind::Mutable, - }; - self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk); - } } place_with_id = self.cat_expr_adjusted(expr, place_with_id, adjustment)?; } @@ -1292,8 +1282,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx adjustment::Adjust::NeverToAny | adjustment::Adjust::Pointer(_) - | adjustment::Adjust::Borrow(_) - | adjustment::Adjust::ReborrowPin(..) => { + | adjustment::Adjust::Borrow(_) => { // Result is an rvalue. Ok(self.cat_rvalue(expr.hir_id, target)) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index f817ca8421473..d50ac8dbaa742 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -337,10 +337,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Adjust::Pointer(_pointer_coercion) => { // FIXME(const_trait_impl): We should probably enforce these. } - Adjust::ReborrowPin(_mutability) => { - // FIXME(const_trait_impl): We could enforce these; they correspond to - // `&mut T: DerefMut` tho, so it's kinda moot. - } Adjust::Borrow(_) => { // No effects to enforce here. } diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 608bc7dffd9c0..add67bd826b1c 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -18,7 +18,8 @@ use rustc_lint::builtin::{ }; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::adjustment::{ - Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion, + Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, + PointerCoercion, }; use rustc_middle::ty::{ self, AssocContainer, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, @@ -243,12 +244,16 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { ty::Ref(_, ty, _) => *ty, _ => bug!("Expected a reference type for argument to Pin"), }; + adjustments.push(Adjustment { + kind: Adjust::Deref(DerefAdjustKind::Pin), + target: inner_ty, + }); Ty::new_pinned_ref(self.tcx, region, inner_ty, mutbl) } _ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"), }; - - adjustments.push(Adjustment { kind: Adjust::ReborrowPin(mutbl), target }); + adjustments + .push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Pin(mutbl)), target }); } None => {} } diff --git a/compiler/rustc_lint/src/autorefs.rs b/compiler/rustc_lint/src/autorefs.rs index 910a2918f9f71..9a374488ab6fa 100644 --- a/compiler/rustc_lint/src/autorefs.rs +++ b/compiler/rustc_lint/src/autorefs.rs @@ -172,7 +172,6 @@ fn has_implicit_borrow(Adjustment { kind, .. }: &Adjustment<'_>) -> Option<(Muta &Adjust::Borrow(AutoBorrow::Ref(mutbl)) => Some((mutbl.into(), false)), Adjust::NeverToAny | Adjust::Pointer(..) - | Adjust::ReborrowPin(..) | Adjust::Deref(DerefAdjustKind::Builtin | DerefAdjustKind::Pin) | Adjust::Borrow(AutoBorrow::RawPtr(..) | AutoBorrow::Pin(..)) => None, } diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 58687be7440b5..3802bde088a54 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -103,10 +103,6 @@ pub enum Adjust { Borrow(AutoBorrow), Pointer(PointerCoercion), - - /// Take a pinned reference and reborrow as a `Pin<&mut T>` or `Pin<&T>`. - // FIXME(pin_ergonomics): This can be replaced with a `Deref(Pin)` followed by a `Borrow(Pin)` - ReborrowPin(hir::Mutability), } #[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index c646b0fc45ea1..21d1551af6a5b 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -218,68 +218,6 @@ impl<'tcx> ThirBuildCx<'tcx> { base: AdtExprBase::None, })); - debug!(?kind); - kind - } - Adjust::ReborrowPin(mutbl) => { - debug!("apply ReborrowPin adjustment"); - // Rewrite `$expr` as `Pin { __pointer: &(mut)? *($expr).__pointer }` - - // We'll need these types later on - let pin_ty_args = match expr.ty.kind() { - ty::Adt(_, args) => args, - _ => bug!("ReborrowPin with non-Pin type"), - }; - let pin_ty = pin_ty_args.iter().next().unwrap().expect_ty(); - let ptr_target_ty = match pin_ty.kind() { - ty::Ref(_, ty, _) => *ty, - _ => bug!("ReborrowPin with non-Ref type"), - }; - - // pointer = ($expr).__pointer - let pointer_target = ExprKind::Field { - lhs: self.thir.exprs.push(expr), - variant_index: FIRST_VARIANT, - name: FieldIdx::ZERO, - }; - let arg = Expr { temp_scope_id, ty: pin_ty, span, kind: pointer_target }; - let arg = self.thir.exprs.push(arg); - - // arg = *pointer - let expr = ExprKind::Deref { arg }; - let arg = self.thir.exprs.push(Expr { - temp_scope_id, - ty: ptr_target_ty, - span, - kind: expr, - }); - - // expr = &mut target - let borrow_kind = match mutbl { - hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default }, - hir::Mutability::Not => BorrowKind::Shared, - }; - let new_pin_target = - Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, ptr_target_ty, mutbl); - let expr = self.thir.exprs.push(Expr { - temp_scope_id, - ty: new_pin_target, - span, - kind: ExprKind::Borrow { borrow_kind, arg }, - }); - - // kind = Pin { __pointer: pointer } - let pin_did = self.tcx.require_lang_item(rustc_hir::LangItem::Pin, span); - let args = self.tcx.mk_args(&[new_pin_target.into()]); - let kind = ExprKind::Adt(Box::new(AdtExpr { - adt_def: self.tcx.adt_def(pin_did), - variant_index: FIRST_VARIANT, - args, - fields: Box::new([FieldExpr { name: FieldIdx::ZERO, expr }]), - user_ty: None, - base: AdtExprBase::None, - })); - debug!(?kind); kind }