Skip to content

Commit 847f1bb

Browse files
committed
refactor: remove Adjust::ReborrowPin
1 parent 0422097 commit 847f1bb

File tree

7 files changed

+16
-87
lines changed

7 files changed

+16
-87
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
853853

854854
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
855855
// add the adjustments.
856-
self.unify_and(a, b, [], Adjust::ReborrowPin(mut_b), ForceLeakCheck::No)
856+
self.unify_and(
857+
a,
858+
b,
859+
[Adjustment { kind: Adjust::Deref(DerefAdjustKind::Pin), target: a_ty }],
860+
Adjust::Borrow(AutoBorrow::Pin(mut_b)),
861+
ForceLeakCheck::No,
862+
)
857863
}
858864

859865
/// Coerce pinned reference to regular reference or vice versa

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

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

13021292
adjustment::Adjust::NeverToAny
13031293
| adjustment::Adjust::Pointer(_)
1304-
| adjustment::Adjust::Borrow(_)
1305-
| adjustment::Adjust::ReborrowPin(..) => {
1294+
| adjustment::Adjust::Borrow(_) => {
13061295
// Result is an rvalue.
13071296
Ok(self.cat_rvalue(expr.hir_id, target))
13081297
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
285285
Adjust::Pointer(_pointer_coercion) => {
286286
// FIXME(const_trait_impl): We should probably enforce these.
287287
}
288-
Adjust::ReborrowPin(_mutability) => {
289-
// FIXME(const_trait_impl): We could enforce these; they correspond to
290-
// `&mut T: DerefMut` tho, so it's kinda moot.
291-
}
292288
Adjust::Borrow(_) => {
293289
// No effects to enforce here.
294290
}

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
@@ -173,7 +173,6 @@ fn has_implicit_borrow(Adjustment { kind, .. }: &Adjustment<'_>) -> Option<(Muta
173173
&Adjust::Borrow(AutoBorrow::Ref(mutbl)) => Some((mutbl.into(), false)),
174174
Adjust::NeverToAny
175175
| Adjust::Pointer(..)
176-
| Adjust::ReborrowPin(..)
177176
| Adjust::Deref(DerefAdjustKind::Builtin | DerefAdjustKind::Pin)
178177
| Adjust::Borrow(AutoBorrow::RawPtr(..) | AutoBorrow::Pin(..)) => None,
179178
}

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
@@ -219,68 +219,6 @@ impl<'tcx> ThirBuildCx<'tcx> {
219219
base: AdtExprBase::None,
220220
}));
221221

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

0 commit comments

Comments
 (0)