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