@@ -807,17 +807,23 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
807807 Ok ( ( ) )
808808 }
809809
810- /// Create an obligation for `ty: Unpin`.
811- fn unpin_obligation ( & self , ty : Ty < ' tcx > ) -> PredicateObligation < ' tcx > {
810+ /// Create an obligation for `ty: Unpin`, where .
811+ fn unpin_obligation (
812+ & self ,
813+ source : Ty < ' tcx > ,
814+ target : Ty < ' tcx > ,
815+ ty : Ty < ' tcx > ,
816+ ) -> PredicateObligation < ' tcx > {
812817 let pred = ty:: TraitRef :: new (
813818 self . tcx ,
814819 self . tcx . require_lang_item ( hir:: LangItem :: Unpin , self . cause . span ) ,
815820 [ ty] ,
816821 ) ;
817- PredicateObligation :: new ( self . tcx , self . cause . clone ( ) , self . param_env , pred)
822+ let cause = self . cause ( self . cause . span , ObligationCauseCode :: Coercion { source, target } ) ;
823+ PredicateObligation :: new ( self . tcx , cause, self . param_env , pred)
818824 }
819825
820- /// Checks if the given types are compatible for coercion to a pinned reference.
826+ /// Checks if the given types are compatible for coercion from a pinned reference to a normal reference.
821827 fn maybe_pin_ref_to_ref ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> Option < CoerceMaybePinnedRef < ' tcx > > {
822828 if !self . tcx . features ( ) . pin_ergonomics ( ) {
823829 return None ;
@@ -847,6 +853,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
847853
848854 coerce_mutbls ( a_mut, b_mut) ?;
849855
856+ let unpin_obligation = self . unpin_obligation ( a, b, a_ty) ;
857+
850858 let a = Ty :: new_ref ( self . tcx , a_r, a_ty, b_mut) ;
851859 let mut coerce = self . unify_and (
852860 a,
@@ -855,7 +863,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
855863 Adjust :: Borrow ( AutoBorrow :: Ref ( AutoBorrowMutability :: new ( b_mut, self . allow_two_phase ) ) ) ,
856864 ForceLeakCheck :: No ,
857865 ) ?;
858- coerce. obligations . push ( self . unpin_obligation ( a_ty ) ) ;
866+ coerce. obligations . push ( unpin_obligation) ;
859867 Ok ( coerce)
860868 }
861869
@@ -902,7 +910,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
902910 // no `Unpin` required when reborrowing a pinned reference to a pinned reference
903911 ty:: Pinnedness :: Pinned => ( DerefAdjustKind :: Pin , None ) ,
904912 // `Unpin` required when reborrowing a non-pinned reference to a pinned reference
905- ty:: Pinnedness :: Not => ( DerefAdjustKind :: Builtin , Some ( self . unpin_obligation ( a_ty) ) ) ,
913+ ty:: Pinnedness :: Not => {
914+ ( DerefAdjustKind :: Builtin , Some ( self . unpin_obligation ( a, b, a_ty) ) )
915+ }
906916 } ;
907917
908918 coerce_mutbls ( a_mut, b_mut) ?;
0 commit comments