@@ -18,8 +18,10 @@ use ty::subst::{Kind, Substs};
1818use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
1919use ty:: error:: { ExpectedFound , TypeError } ;
2020use std:: rc:: Rc ;
21+ use std:: iter;
2122use syntax:: abi;
2223use hir as ast;
24+ use rustc_data_structures:: accumulate_vec:: AccumulateVec ;
2325
2426pub type RelateResult < ' tcx , T > = Result < T , TypeError < ' tcx > > ;
2527
@@ -180,21 +182,30 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
180182 -> RelateResult < ' tcx , ty:: FnSig < ' tcx > >
181183 where R : TypeRelation < ' a , ' gcx , ' tcx > , ' gcx : ' a +' tcx , ' tcx : ' a
182184 {
183- if a. variadic ( ) != b. variadic ( ) {
185+ if a. variadic != b. variadic {
184186 return Err ( TypeError :: VariadicMismatch (
185- expected_found ( relation, & a. variadic ( ) , & b. variadic ( ) ) ) ) ;
187+ expected_found ( relation, & a. variadic , & b. variadic ) ) ) ;
186188 }
187189
188190 if a. inputs ( ) . len ( ) != b. inputs ( ) . len ( ) {
189191 return Err ( TypeError :: ArgCount ) ;
190192 }
191193
192- let inputs = a. inputs ( ) . iter ( ) . zip ( b. inputs ( ) ) . map ( |( & a, & b) | {
193- relation. relate_with_variance ( ty:: Contravariant , & a, & b)
194- } ) . collect :: < Result < Vec < _ > , _ > > ( ) ?;
195- let output = relation. relate ( & a. output ( ) , & b. output ( ) ) ?;
196-
197- Ok ( ty:: FnSig :: new ( inputs, output, a. variadic ( ) ) )
194+ let inputs_and_output = a. inputs ( ) . iter ( ) . cloned ( )
195+ . zip ( b. inputs ( ) . iter ( ) . cloned ( ) )
196+ . map ( |x| ( x, false ) )
197+ . chain ( iter:: once ( ( ( a. output ( ) , b. output ( ) ) , true ) ) )
198+ . map ( |( ( a, b) , is_output) | {
199+ if is_output {
200+ relation. relate ( & a, & b)
201+ } else {
202+ relation. relate_with_variance ( ty:: Contravariant , & a, & b)
203+ }
204+ } ) . collect :: < Result < AccumulateVec < [ _ ; 8 ] > , _ > > ( ) ?;
205+ Ok ( ty:: FnSig {
206+ inputs_and_output : relation. tcx ( ) . intern_type_list ( & inputs_and_output) ,
207+ variadic : a. variadic
208+ } )
198209 }
199210}
200211
0 commit comments