@@ -123,7 +123,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
123123 Coerce { fcx, cause, allow_two_phase, use_lub : false , coerce_never }
124124 }
125125
126- fn unify_raw ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> InferResult < ' tcx , Ty < ' tcx > > {
126+ fn unify_raw ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > , leak_check : bool ) -> InferResult < ' tcx , Ty < ' tcx > > {
127127 debug ! ( "unify(a: {:?}, b: {:?}, use_lub: {})" , a, b, self . use_lub) ;
128128 self . commit_if_ok ( |snapshot| {
129129 let outer_universe = self . infcx . universe ( ) ;
@@ -169,15 +169,17 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
169169 //
170170 // FIXME: Ideally the actual `eq/sub/lub` would handle leak checks
171171 // themselves whenever a binder is entered.
172- self . leak_check ( outer_universe, Some ( snapshot) ) ?;
172+ if leak_check || self . use_lub {
173+ self . leak_check ( outer_universe, Some ( snapshot) ) ?;
174+ }
173175
174176 res
175177 } )
176178 }
177179
178180 /// Unify two types (using sub or lub).
179181 fn unify ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
180- self . unify_raw ( a, b)
182+ self . unify_raw ( a, b, false )
181183 . and_then ( |InferOk { value : ty, obligations } | success ( vec ! [ ] , ty, obligations) )
182184 }
183185
@@ -188,8 +190,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
188190 b : Ty < ' tcx > ,
189191 adjustments : impl IntoIterator < Item = Adjustment < ' tcx > > ,
190192 final_adjustment : Adjust ,
193+ leak_check : bool ,
191194 ) -> CoerceResult < ' tcx > {
192- self . unify_raw ( a, b) . and_then ( |InferOk { value : ty, obligations } | {
195+ self . unify_raw ( a, b, leak_check ) . and_then ( |InferOk { value : ty, obligations } | {
193196 success (
194197 adjustments
195198 . into_iter ( )
@@ -405,7 +408,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
405408 // the `Target` type with the pointee of `b`. This is necessary
406409 // to properly account for the differing variances of the pointees
407410 // of `&` vs `&mut` references.
408- match self . unify_raw ( autorefd_deref_ty, b) {
411+ match self . unify_raw ( autorefd_deref_ty, b, false ) {
409412 Ok ( ok) => Some ( ok) ,
410413 Err ( err) => {
411414 if first_error. is_none ( ) {
@@ -602,6 +605,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
602605 target,
603606 reborrow. into_iter ( ) . flat_map ( |( deref, autoref) | [ deref, autoref] ) ,
604607 Adjust :: Pointer ( PointerCoercion :: Unsize ) ,
608+ false ,
605609 ) ?;
606610
607611 // Create an obligation for `Source: CoerceUnsized<Target>`.
@@ -816,7 +820,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
816820
817821 // To complete the reborrow, we need to make sure we can unify the inner types, and if so we
818822 // add the adjustments.
819- self . unify_and ( a, b, [ ] , Adjust :: ReborrowPin ( mut_b) )
823+ self . unify_and ( a, b, [ ] , Adjust :: ReborrowPin ( mut_b) , false )
820824 }
821825
822826 fn coerce_from_fn_pointer (
@@ -832,7 +836,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
832836 ty:: FnPtr ( _, b_hdr) if a_sig. safety ( ) . is_safe ( ) && b_hdr. safety . is_unsafe ( ) => {
833837 let a = self . tcx . safe_to_unsafe_fn_ty ( a_sig) ;
834838 let adjust = Adjust :: Pointer ( PointerCoercion :: UnsafeFnPointer ) ;
835- self . unify_and ( a, b, [ ] , adjust)
839+ self . unify_and ( a, b, [ ] , adjust, true )
836840 }
837841 _ => self . unify ( a, b) ,
838842 }
@@ -854,7 +858,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
854858 let a = Ty :: new_fn_ptr ( self . tcx , a_sig) ;
855859
856860 let adjust = Adjust :: Pointer ( PointerCoercion :: ReifyFnPointer ( b_hdr. safety ) ) ;
857- let InferOk { value, obligations : o2 } = self . unify_and ( a, b, [ ] , adjust) ?;
861+ let InferOk { value, obligations : o2 } = self . unify_and ( a, b, [ ] , adjust, true ) ?;
858862
859863 obligations. extend ( o2) ;
860864 Ok ( InferOk { value, obligations } )
@@ -880,7 +884,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
880884 // We don't use `self.coerce_fnptrs` as handling `fn` to `unsafe fn`
881885 // was trivial to do so ourselves.
882886 let adjust = Adjust :: Pointer ( PointerCoercion :: ClosureFnPointer ( safety) ) ;
883- self . unify_and ( pointer_ty, b, [ ] , adjust)
887+ self . unify_and ( pointer_ty, b, [ ] , adjust, true )
884888 }
885889 _ => self . unify ( a, b) ,
886890 }
@@ -914,9 +918,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
914918 b,
915919 [ Adjustment { kind : Adjust :: Deref ( None ) , target : mt_a. ty } ] ,
916920 Adjust :: Borrow ( AutoBorrow :: RawPtr ( mutbl_b) ) ,
921+ false ,
917922 )
918923 } else if mt_a. mutbl != mutbl_b {
919- self . unify_and ( a_raw, b, [ ] , Adjust :: Pointer ( PointerCoercion :: MutToConstPointer ) )
924+ self . unify_and ( a_raw, b, [ ] , Adjust :: Pointer ( PointerCoercion :: MutToConstPointer ) , false )
920925 } else {
921926 self . unify ( a_raw, b)
922927 }
@@ -1017,7 +1022,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10171022 // We don't ever need two-phase here since we throw out the result of the coercion.
10181023 let coerce = Coerce :: new ( self , cause, AllowTwoPhase :: No , true ) ;
10191024 coerce. autoderef ( DUMMY_SP , expr_ty) . find_map ( |( ty, steps) | {
1020- self . probe ( |_| coerce. unify_raw ( ty, target) ) . ok ( ) . map ( |_| steps)
1025+ self . probe ( |_| coerce. unify_raw ( ty, target, false ) ) . ok ( ) . map ( |_| steps)
10211026 } )
10221027 }
10231028
0 commit comments