@@ -163,12 +163,18 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
163
163
& self ,
164
164
a : Ty < ' tcx > ,
165
165
b : Ty < ' tcx > ,
166
- mut adjustments : Vec < Adjustment < ' tcx > > ,
166
+ adjustments : impl IntoIterator < Item = Adjustment < ' tcx > > ,
167
167
final_adjustment : Adjust ,
168
168
) -> CoerceResult < ' tcx > {
169
169
self . unify_raw ( a, b) . and_then ( |InferOk { value : ty, obligations } | {
170
- adjustments. push ( Adjustment { target : ty, kind : final_adjustment } ) ;
171
- success ( adjustments, ty, obligations)
170
+ success (
171
+ adjustments
172
+ . into_iter ( )
173
+ . chain ( std:: iter:: once ( Adjustment { target : ty, kind : final_adjustment } ) )
174
+ . collect ( ) ,
175
+ ty,
176
+ obligations,
177
+ )
172
178
} )
173
179
}
174
180
@@ -579,15 +585,18 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
579
585
// We only have the latter, so we use an inference variable
580
586
// for the former and let type inference do the rest.
581
587
let coerce_target = self . next_ty_var ( self . cause . span ) ;
582
- let mut coercion = self . unify_and (
583
- coerce_target,
584
- target,
585
- match reborrow {
586
- None => vec ! [ ] ,
587
- Some ( ( ref deref, ref autoref) ) => vec ! [ deref. clone( ) , autoref. clone( ) ] ,
588
- } ,
589
- Adjust :: Pointer ( PointerCoercion :: Unsize ) ,
590
- ) ?;
588
+
589
+ let mut coercion = match reborrow {
590
+ None => {
591
+ self . unify_and ( coerce_target, target, [ ] , Adjust :: Pointer ( PointerCoercion :: Unsize ) ) ?
592
+ }
593
+ Some ( ( ref deref, ref autoref) ) => self . unify_and (
594
+ coerce_target,
595
+ target,
596
+ [ deref. clone ( ) , autoref. clone ( ) ] ,
597
+ Adjust :: Pointer ( PointerCoercion :: Unsize ) ,
598
+ ) ?,
599
+ } ;
591
600
592
601
let mut selcx = traits:: SelectionContext :: new ( self ) ;
593
602
@@ -810,7 +819,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
810
819
811
820
// To complete the reborrow, we need to make sure we can unify the inner types, and if so we
812
821
// add the adjustments.
813
- self . unify_and ( a, b, vec ! [ ] , Adjust :: ReborrowPin ( mut_b) )
822
+ self . unify_and ( a, b, [ ] , Adjust :: ReborrowPin ( mut_b) )
814
823
}
815
824
816
825
fn coerce_from_safe_fn (
@@ -827,22 +836,24 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
827
836
&& hdr_b. safety . is_unsafe ( )
828
837
{
829
838
let unsafe_a = self . tcx . safe_to_unsafe_fn_ty ( fn_ty_a) ;
830
- let adjustments = match adjustment {
831
- Some ( kind) => {
832
- vec ! [ Adjustment { kind, target: Ty :: new_fn_ptr( self . tcx, fn_ty_a) } ]
833
- }
834
- None => vec ! [ ] ,
835
- } ;
836
- self . unify_and (
837
- unsafe_a,
838
- b,
839
- adjustments,
840
- Adjust :: Pointer ( PointerCoercion :: UnsafeFnPointer ) ,
841
- )
839
+ match adjustment {
840
+ Some ( kind) => self . unify_and (
841
+ unsafe_a,
842
+ b,
843
+ [ Adjustment { kind, target : Ty :: new_fn_ptr ( self . tcx , fn_ty_a) } ] ,
844
+ Adjust :: Pointer ( PointerCoercion :: UnsafeFnPointer ) ,
845
+ ) ,
846
+ None => self . unify_and (
847
+ unsafe_a,
848
+ b,
849
+ [ ] ,
850
+ Adjust :: Pointer ( PointerCoercion :: UnsafeFnPointer ) ,
851
+ ) ,
852
+ }
842
853
} else {
843
854
let a = Ty :: new_fn_ptr ( self . tcx , fn_ty_a) ;
844
855
match adjustment {
845
- Some ( adjust) => self . unify_and ( a, b, vec ! [ ] , adjust) ,
856
+ Some ( adjust) => self . unify_and ( a, b, [ ] , adjust) ,
846
857
None => self . unify ( a, b) ,
847
858
}
848
859
} ;
@@ -971,7 +982,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
971
982
self . unify_and (
972
983
pointer_ty,
973
984
b,
974
- vec ! [ ] ,
985
+ [ ] ,
975
986
Adjust :: Pointer ( PointerCoercion :: ClosureFnPointer ( safety) ) ,
976
987
)
977
988
}
@@ -1003,11 +1014,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
1003
1014
self . unify_and (
1004
1015
a_raw,
1005
1016
b,
1006
- vec ! [ Adjustment { kind: Adjust :: Deref ( None ) , target: mt_a. ty } ] ,
1017
+ [ Adjustment { kind : Adjust :: Deref ( None ) , target : mt_a. ty } ] ,
1007
1018
Adjust :: Borrow ( AutoBorrow :: RawPtr ( mutbl_b) ) ,
1008
1019
)
1009
1020
} else if mt_a. mutbl != mutbl_b {
1010
- self . unify_and ( a_raw, b, vec ! [ ] , Adjust :: Pointer ( PointerCoercion :: MutToConstPointer ) )
1021
+ self . unify_and ( a_raw, b, [ ] , Adjust :: Pointer ( PointerCoercion :: MutToConstPointer ) )
1011
1022
} else {
1012
1023
self . unify ( a_raw, b)
1013
1024
}
0 commit comments