@@ -474,6 +474,31 @@ impl<'tcx> Cx<'tcx> {
474
474
ExprKind :: RawBorrow { mutability, arg : self . mirror_expr ( arg) }
475
475
}
476
476
477
+ // make `&pin mut $expr` and `&pin const $expr` into `Pin { __pointer: &mut $expr }`
478
+ // and `Pin { __pointer: &$expr }`
479
+ hir:: ExprKind :: AddrOf ( hir:: BorrowKind :: Pin , mutbl, arg) => match expr_ty. kind ( ) {
480
+ & ty:: Adt ( adt_def, args)
481
+ if tcx. is_lang_item ( adt_def. did ( ) , rustc_hir:: LangItem :: Pin ) =>
482
+ {
483
+ let arg = self . mirror_expr ( arg) ;
484
+ let expr = self . thir . exprs . push ( Expr {
485
+ temp_lifetime : TempLifetime { temp_lifetime, backwards_incompatible } ,
486
+ ty : args. type_at ( 0 ) ,
487
+ span : expr. span ,
488
+ kind : ExprKind :: Borrow { borrow_kind : mutbl. to_borrow_kind ( ) , arg } ,
489
+ } ) ;
490
+ ExprKind :: Adt ( Box :: new ( AdtExpr {
491
+ adt_def,
492
+ variant_index : FIRST_VARIANT ,
493
+ args,
494
+ fields : Box :: new ( [ FieldExpr { name : FieldIdx :: from ( 0u32 ) , expr } ] ) ,
495
+ user_ty : None ,
496
+ base : AdtExprBase :: None ,
497
+ } ) )
498
+ }
499
+ _ => span_bug ! ( expr. span, "unexpected type for pinned borrow: {:?}" , expr_ty) ,
500
+ } ,
501
+
477
502
hir:: ExprKind :: Block ( blk, _) => ExprKind :: Block { block : self . mirror_block ( blk) } ,
478
503
479
504
hir:: ExprKind :: Assign ( lhs, rhs, _) => {
0 commit comments