@@ -117,6 +117,7 @@ impl<'a, 'gcx, 'tcx> Pattern<'tcx> {
117117 if !pcx. errors . is_empty ( ) {
118118 span_bug ! ( pat. span, "encountered errors lowering pattern: {:?}" , pcx. errors)
119119 }
120+ debug ! ( "Pattern::from_hir({:?}) = {:?}" , pat, result) ;
120121 result
121122 }
122123}
@@ -346,6 +347,40 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
346347 pat. as_ref ( ) . map ( |p| self . lower_pattern ( p) )
347348 }
348349
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+
349384 fn slice_or_array_pattern (
350385 & mut self ,
351386 span : Span ,
@@ -355,24 +390,22 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
355390 suffix : & [ P < hir:: Pat > ] )
356391 -> PatternKind < ' tcx >
357392 {
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+
358399 match ty. sty {
359400 ty:: TySlice ( ..) => {
360401 // 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 }
366403 }
367404
368405 ty:: TyArray ( _, len) => {
369406 // fixed-length array
370407 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 }
376409 }
377410
378411 _ => {
0 commit comments