Skip to content

Commit f78cbce

Browse files
committed
refactor: remove Adjust::ReborrowPin
1 parent b49ecc9 commit f78cbce

6 files changed

Lines changed: 9 additions & 86 deletions

File tree

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,16 +751,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
751751
adjustment::Adjust::Borrow(ref autoref) => {
752752
self.walk_autoref(expr, &place_with_id, autoref);
753753
}
754-
755-
adjustment::Adjust::ReborrowPin(mutbl) => {
756-
// Reborrowing a Pin is like a combinations of a deref and a borrow, so we do
757-
// both.
758-
let bk = match mutbl {
759-
ty::Mutability::Not => ty::BorrowKind::Immutable,
760-
ty::Mutability::Mut => ty::BorrowKind::Mutable,
761-
};
762-
self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
763-
}
764754
}
765755
place_with_id = self.cat_expr_adjusted(expr, place_with_id, adjustment)?;
766756
}
@@ -1292,8 +1282,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12921282

12931283
adjustment::Adjust::NeverToAny
12941284
| adjustment::Adjust::Pointer(_)
1295-
| adjustment::Adjust::Borrow(_)
1296-
| adjustment::Adjust::ReborrowPin(..) => {
1285+
| adjustment::Adjust::Borrow(_) => {
12971286
// Result is an rvalue.
12981287
Ok(self.cat_rvalue(expr.hir_id, target))
12991288
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
337337
Adjust::Pointer(_pointer_coercion) => {
338338
// FIXME(const_trait_impl): We should probably enforce these.
339339
}
340-
Adjust::ReborrowPin(_mutability) => {
341-
// FIXME(const_trait_impl): We could enforce these; they correspond to
342-
// `&mut T: DerefMut` tho, so it's kinda moot.
343-
}
344340
Adjust::Borrow(_) => {
345341
// No effects to enforce here.
346342
}

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use rustc_lint::builtin::{
1818
};
1919
use rustc_middle::traits::ObligationCauseCode;
2020
use rustc_middle::ty::adjustment::{
21-
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
21+
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
22+
PointerCoercion,
2223
};
2324
use rustc_middle::ty::{
2425
self, AssocContainer, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt,
@@ -243,12 +244,16 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
243244
ty::Ref(_, ty, _) => *ty,
244245
_ => bug!("Expected a reference type for argument to Pin"),
245246
};
247+
adjustments.push(Adjustment {
248+
kind: Adjust::Deref(DerefAdjustKind::Pin),
249+
target: inner_ty,
250+
});
246251
Ty::new_pinned_ref(self.tcx, region, inner_ty, mutbl)
247252
}
248253
_ => bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"),
249254
};
250-
251-
adjustments.push(Adjustment { kind: Adjust::ReborrowPin(mutbl), target });
255+
adjustments
256+
.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Pin(mutbl)), target });
252257
}
253258
None => {}
254259
}

compiler/rustc_lint/src/autorefs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ fn has_implicit_borrow(Adjustment { kind, .. }: &Adjustment<'_>) -> Option<(Muta
172172
&Adjust::Borrow(AutoBorrow::Ref(mutbl)) => Some((mutbl.into(), false)),
173173
Adjust::NeverToAny
174174
| Adjust::Pointer(..)
175-
| Adjust::ReborrowPin(..)
176175
| Adjust::Deref(DerefAdjustKind::Builtin | DerefAdjustKind::Pin)
177176
| Adjust::Borrow(AutoBorrow::RawPtr(..) | AutoBorrow::Pin(..)) => None,
178177
}

compiler/rustc_middle/src/ty/adjustment.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ pub enum Adjust {
103103
Borrow(AutoBorrow),
104104

105105
Pointer(PointerCoercion),
106-
107-
/// Take a pinned reference and reborrow as a `Pin<&mut T>` or `Pin<&T>`.
108-
// FIXME(pin_ergonomics): This can be replaced with a `Deref(Pin)` followed by a `Borrow(Pin)`
109-
ReborrowPin(hir::Mutability),
110106
}
111107

112108
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -218,68 +218,6 @@ impl<'tcx> ThirBuildCx<'tcx> {
218218
base: AdtExprBase::None,
219219
}));
220220

221-
debug!(?kind);
222-
kind
223-
}
224-
Adjust::ReborrowPin(mutbl) => {
225-
debug!("apply ReborrowPin adjustment");
226-
// Rewrite `$expr` as `Pin { __pointer: &(mut)? *($expr).__pointer }`
227-
228-
// We'll need these types later on
229-
let pin_ty_args = match expr.ty.kind() {
230-
ty::Adt(_, args) => args,
231-
_ => bug!("ReborrowPin with non-Pin type"),
232-
};
233-
let pin_ty = pin_ty_args.iter().next().unwrap().expect_ty();
234-
let ptr_target_ty = match pin_ty.kind() {
235-
ty::Ref(_, ty, _) => *ty,
236-
_ => bug!("ReborrowPin with non-Ref type"),
237-
};
238-
239-
// pointer = ($expr).__pointer
240-
let pointer_target = ExprKind::Field {
241-
lhs: self.thir.exprs.push(expr),
242-
variant_index: FIRST_VARIANT,
243-
name: FieldIdx::ZERO,
244-
};
245-
let arg = Expr { temp_scope_id, ty: pin_ty, span, kind: pointer_target };
246-
let arg = self.thir.exprs.push(arg);
247-
248-
// arg = *pointer
249-
let expr = ExprKind::Deref { arg };
250-
let arg = self.thir.exprs.push(Expr {
251-
temp_scope_id,
252-
ty: ptr_target_ty,
253-
span,
254-
kind: expr,
255-
});
256-
257-
// expr = &mut target
258-
let borrow_kind = match mutbl {
259-
hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
260-
hir::Mutability::Not => BorrowKind::Shared,
261-
};
262-
let new_pin_target =
263-
Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, ptr_target_ty, mutbl);
264-
let expr = self.thir.exprs.push(Expr {
265-
temp_scope_id,
266-
ty: new_pin_target,
267-
span,
268-
kind: ExprKind::Borrow { borrow_kind, arg },
269-
});
270-
271-
// kind = Pin { __pointer: pointer }
272-
let pin_did = self.tcx.require_lang_item(rustc_hir::LangItem::Pin, span);
273-
let args = self.tcx.mk_args(&[new_pin_target.into()]);
274-
let kind = ExprKind::Adt(Box::new(AdtExpr {
275-
adt_def: self.tcx.adt_def(pin_did),
276-
variant_index: FIRST_VARIANT,
277-
args,
278-
fields: Box::new([FieldExpr { name: FieldIdx::ZERO, expr }]),
279-
user_ty: None,
280-
base: AdtExprBase::None,
281-
}));
282-
283221
debug!(?kind);
284222
kind
285223
}

0 commit comments

Comments
 (0)