@@ -798,9 +798,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
798798 // Right now we can only reborrow if this is a `Pin<&mut T>`.
799799 let extract_pin_mut = |ty : Ty < ' tcx > | {
800800 // Get the T out of Pin<T>
801- let ty = match ty. kind ( ) {
801+ let ( pin , ty ) = match ty. kind ( ) {
802802 ty:: Adt ( pin, args) if self . tcx . is_lang_item ( pin. did ( ) , hir:: LangItem :: Pin ) => {
803- args[ 0 ] . expect_ty ( )
803+ ( * pin , args[ 0 ] . expect_ty ( ) )
804804 }
805805 _ => {
806806 debug ! ( "can't reborrow {:?} as pinned" , ty) ;
@@ -809,24 +809,30 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
809809 } ;
810810 // Make sure the T is something we understand (just `&mut U` for now)
811811 match ty. kind ( ) {
812- ty:: Ref ( region, ty, ty :: Mutability :: Mut ) => Ok ( ( * region, * ty) ) ,
812+ ty:: Ref ( region, ty, mutbl ) => Ok ( ( pin , * region, * ty, * mutbl ) ) ,
813813 _ => {
814814 debug ! ( "can't reborrow pin of inner type {:?}" , ty) ;
815815 Err ( TypeError :: Mismatch )
816816 }
817817 }
818818 } ;
819819
820- let ( _, _a_ty) = extract_pin_mut ( a) ?;
821- let ( b_region, _b_ty) = extract_pin_mut ( b) ?;
820+ let ( pin, a_region, a_ty, mut_a) = extract_pin_mut ( a) ?;
821+ let ( _, b_region, _b_ty, mut_b) = extract_pin_mut ( b) ?;
822+
823+ coerce_mutbls ( mut_a, mut_b) ?;
824+
825+ // update a with b's mutability since we'll be coercing mutability
826+ let a = Ty :: new_adt (
827+ self . tcx ,
828+ pin,
829+ self . tcx . mk_args ( & [ Ty :: new_ref ( self . tcx , a_region, a_ty, mut_b) . into ( ) ] ) ,
830+ ) ;
822831
823832 // To complete the reborrow, we need to make sure we can unify the inner types, and if so we
824833 // add the adjustments.
825834 self . unify_and ( a, b, |_inner_ty| {
826- vec ! [ Adjustment {
827- kind: Adjust :: ReborrowPin ( b_region, hir:: Mutability :: Mut ) ,
828- target: b,
829- } ]
835+ vec ! [ Adjustment { kind: Adjust :: ReborrowPin ( b_region, mut_b) , target: b } ]
830836 } )
831837 }
832838
0 commit comments