@@ -111,20 +111,29 @@ impl<'a> InferenceContext<'a> {
111111 let expected = expected;
112112
113113 let ty = match & body[ pat] {
114- Pat :: Tuple { ref args, .. } => {
114+ Pat :: Tuple { ref args, ellipsis } => {
115115 let expectations = match expected. as_tuple ( ) {
116116 Some ( parameters) => & * parameters. 0 ,
117117 _ => & [ ] ,
118118 } ;
119- let expectations_iter = expectations. iter ( ) . chain ( repeat ( & Ty :: Unknown ) ) ;
120119
121- let inner_tys = args
122- . iter ( )
123- . zip ( expectations_iter)
124- . map ( |( & pat, ty) | self . infer_pat ( pat, ty, default_bm) )
125- . collect ( ) ;
120+ let ( pre, post) = match ellipsis {
121+ & Some ( idx) => args. split_at ( idx) ,
122+ None => ( & args[ ..] , & [ ] [ ..] ) ,
123+ } ;
124+ let uncovered_range = pre. len ( ) ..expectations. len ( ) . saturating_sub ( post. len ( ) ) ;
125+ let mut expectations_iter = expectations. iter ( ) . chain ( repeat ( & Ty :: Unknown ) ) ;
126+ let mut infer_pat = |( & pat, ty) | self . infer_pat ( pat, ty, default_bm) ;
127+
128+ let mut inner_tys = Vec :: with_capacity ( expectations. len ( ) ) ;
129+ inner_tys. extend ( pre. iter ( ) . zip ( expectations_iter. by_ref ( ) ) . map ( & mut infer_pat) ) ;
130+ inner_tys. extend ( expectations_iter. by_ref ( ) . take ( uncovered_range. len ( ) ) . cloned ( ) ) ;
131+ inner_tys. extend ( post. iter ( ) . zip ( expectations_iter) . map ( infer_pat) ) ;
126132
127- Ty :: apply ( TypeCtor :: Tuple { cardinality : args. len ( ) as u16 } , Substs ( inner_tys) )
133+ Ty :: apply (
134+ TypeCtor :: Tuple { cardinality : inner_tys. len ( ) as u16 } ,
135+ Substs ( inner_tys. into ( ) ) ,
136+ )
128137 }
129138 Pat :: Or ( ref pats) => {
130139 if let Some ( ( first_pat, rest) ) = pats. split_first ( ) {
0 commit comments