@@ -117,6 +117,7 @@ impl<'a, 'gcx, 'tcx> Pattern<'tcx> {
117
117
if !pcx. errors . is_empty ( ) {
118
118
span_bug ! ( pat. span, "encountered errors lowering pattern: {:?}" , pcx. errors)
119
119
}
120
+ debug ! ( "Pattern::from_hir({:?}) = {:?}" , pat, result) ;
120
121
result
121
122
}
122
123
}
@@ -346,6 +347,40 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
346
347
pat. as_ref ( ) . map ( |p| self . lower_pattern ( p) )
347
348
}
348
349
350
+ fn flatten_nested_slice_patterns (
351
+ & mut self ,
352
+ prefix : Vec < Pattern < ' tcx > > ,
353
+ slice : Option < Pattern < ' tcx > > ,
354
+ suffix : Vec < Pattern < ' tcx > > )
355
+ -> ( Vec < Pattern < ' tcx > > , Option < Pattern < ' tcx > > , Vec < Pattern < ' tcx > > )
356
+ {
357
+ let orig_slice = match slice {
358
+ Some ( orig_slice) => orig_slice,
359
+ None => return ( prefix, slice, suffix)
360
+ } ;
361
+ let orig_prefix = prefix;
362
+ let orig_suffix = suffix;
363
+
364
+ // dance because of intentional borrow-checker stupidity.
365
+ let kind = * orig_slice. kind ;
366
+ match kind {
367
+ PatternKind :: Slice { prefix, slice, mut suffix } |
368
+ PatternKind :: Array { prefix, slice, mut suffix } => {
369
+ let mut orig_prefix = orig_prefix;
370
+
371
+ orig_prefix. extend ( prefix) ;
372
+ suffix. extend ( orig_suffix) ;
373
+
374
+ ( orig_prefix, slice, suffix)
375
+ }
376
+ _ => {
377
+ ( orig_prefix, Some ( Pattern {
378
+ kind : box kind, ..orig_slice
379
+ } ) , orig_suffix)
380
+ }
381
+ }
382
+ }
383
+
349
384
fn slice_or_array_pattern (
350
385
& mut self ,
351
386
span : Span ,
@@ -355,24 +390,22 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
355
390
suffix : & [ P < hir:: Pat > ] )
356
391
-> PatternKind < ' tcx >
357
392
{
393
+ let prefix = self . lower_patterns ( prefix) ;
394
+ let slice = self . lower_opt_pattern ( slice) ;
395
+ let suffix = self . lower_patterns ( suffix) ;
396
+ let ( prefix, slice, suffix) =
397
+ self . flatten_nested_slice_patterns ( prefix, slice, suffix) ;
398
+
358
399
match ty. sty {
359
400
ty:: TySlice ( ..) => {
360
401
// matching a slice or fixed-length array
361
- PatternKind :: Slice {
362
- prefix : self . lower_patterns ( prefix) ,
363
- slice : self . lower_opt_pattern ( slice) ,
364
- suffix : self . lower_patterns ( suffix) ,
365
- }
402
+ PatternKind :: Slice { prefix : prefix, slice : slice, suffix : suffix }
366
403
}
367
404
368
405
ty:: TyArray ( _, len) => {
369
406
// fixed-length array
370
407
assert ! ( len >= prefix. len( ) + suffix. len( ) ) ;
371
- PatternKind :: Array {
372
- prefix : self . lower_patterns ( prefix) ,
373
- slice : self . lower_opt_pattern ( slice) ,
374
- suffix : self . lower_patterns ( suffix) ,
375
- }
408
+ PatternKind :: Array { prefix : prefix, slice : slice, suffix : suffix }
376
409
}
377
410
378
411
_ => {
0 commit comments