@@ -798,9 +798,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
798
798
// Right now we can only reborrow if this is a `Pin<&mut T>`.
799
799
let extract_pin_mut = |ty : Ty < ' tcx > | {
800
800
// Get the T out of Pin<T>
801
- let ty = match ty. kind ( ) {
801
+ let ( pin , ty ) = match ty. kind ( ) {
802
802
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 ( ) )
804
804
}
805
805
_ => {
806
806
debug ! ( "can't reborrow {:?} as pinned" , ty) ;
@@ -809,24 +809,30 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
809
809
} ;
810
810
// Make sure the T is something we understand (just `&mut U` for now)
811
811
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 ) ) ,
813
813
_ => {
814
814
debug ! ( "can't reborrow pin of inner type {:?}" , ty) ;
815
815
Err ( TypeError :: Mismatch )
816
816
}
817
817
}
818
818
} ;
819
819
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
+ ) ;
822
831
823
832
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
824
833
// add the adjustments.
825
834
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 } ]
830
836
} )
831
837
}
832
838
0 commit comments