@@ -18,8 +18,10 @@ use ty::subst::{Kind, Substs};
18
18
use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
19
19
use ty:: error:: { ExpectedFound , TypeError } ;
20
20
use std:: rc:: Rc ;
21
+ use std:: iter;
21
22
use syntax:: abi;
22
23
use hir as ast;
24
+ use rustc_data_structures:: accumulate_vec:: AccumulateVec ;
23
25
24
26
pub type RelateResult < ' tcx , T > = Result < T , TypeError < ' tcx > > ;
25
27
@@ -180,21 +182,30 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
180
182
-> RelateResult < ' tcx , ty:: FnSig < ' tcx > >
181
183
where R : TypeRelation < ' a , ' gcx , ' tcx > , ' gcx : ' a +' tcx , ' tcx : ' a
182
184
{
183
- if a. variadic ( ) != b. variadic ( ) {
185
+ if a. variadic != b. variadic {
184
186
return Err ( TypeError :: VariadicMismatch (
185
- expected_found ( relation, & a. variadic ( ) , & b. variadic ( ) ) ) ) ;
187
+ expected_found ( relation, & a. variadic , & b. variadic ) ) ) ;
186
188
}
187
189
188
190
if a. inputs ( ) . len ( ) != b. inputs ( ) . len ( ) {
189
191
return Err ( TypeError :: ArgCount ) ;
190
192
}
191
193
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
+ } )
198
209
}
199
210
}
200
211
0 commit comments