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