@@ -6,6 +6,7 @@ use chalk_ir::Mutability;
6
6
use hir_def:: {
7
7
expr:: { BindingAnnotation , Expr , Literal , Pat , PatId , RecordFieldPat } ,
8
8
path:: Path ,
9
+ type_ref:: ConstScalar ,
9
10
} ;
10
11
use hir_expand:: name:: Name ;
11
12
@@ -14,7 +15,8 @@ use crate::{
14
15
Adjust , Adjustment , AutoBorrow , BindingMode , Expectation , InferenceContext , TypeMismatch ,
15
16
} ,
16
17
lower:: lower_to_chalk_mutability,
17
- static_lifetime, Interner , Substitution , Ty , TyBuilder , TyExt , TyKind ,
18
+ static_lifetime, ConcreteConst , ConstValue , Interner , Substitution , Ty , TyBuilder , TyExt ,
19
+ TyKind ,
18
20
} ;
19
21
20
22
impl < ' a > InferenceContext < ' a > {
@@ -232,16 +234,28 @@ impl<'a> InferenceContext<'a> {
232
234
self . infer_pat ( pat_id, & elem_ty, default_bm) ;
233
235
}
234
236
235
- let pat_ty = match expected. kind ( Interner ) {
236
- TyKind :: Array ( _, const_) => TyKind :: Array ( elem_ty, const_. clone ( ) ) ,
237
- _ => TyKind :: Slice ( elem_ty) ,
238
- }
239
- . intern ( Interner ) ;
240
237
if let & Some ( slice_pat_id) = slice {
241
- self . infer_pat ( slice_pat_id, & pat_ty, default_bm) ;
238
+ let rest_pat_ty = match expected. kind ( Interner ) {
239
+ TyKind :: Array ( _, length) => {
240
+ let length = match length. data ( Interner ) . value {
241
+ ConstValue :: Concrete ( ConcreteConst {
242
+ interned : ConstScalar :: Usize ( length) ,
243
+ } ) => length. checked_sub ( ( prefix. len ( ) + suffix. len ( ) ) as u64 ) ,
244
+ _ => None ,
245
+ } ;
246
+ TyKind :: Array ( elem_ty. clone ( ) , crate :: consteval:: usize_const ( length) )
247
+ }
248
+ _ => TyKind :: Slice ( elem_ty. clone ( ) ) ,
249
+ }
250
+ . intern ( Interner ) ;
251
+ self . infer_pat ( slice_pat_id, & rest_pat_ty, default_bm) ;
242
252
}
243
253
244
- pat_ty
254
+ match expected. kind ( Interner ) {
255
+ TyKind :: Array ( _, const_) => TyKind :: Array ( elem_ty, const_. clone ( ) ) ,
256
+ _ => TyKind :: Slice ( elem_ty) ,
257
+ }
258
+ . intern ( Interner )
245
259
}
246
260
Pat :: Wild => expected. clone ( ) ,
247
261
Pat :: Range { start, end } => {
0 commit comments