@@ -368,31 +368,34 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
368
368
fn check_exhaustive ( cx : & MatchCheckCtxt , sp : Span , matrix : & Matrix , source : hir:: MatchSource ) {
369
369
match is_useful ( cx, matrix, & [ DUMMY_WILD_PAT ] , ConstructWitness ) {
370
370
UsefulWithWitness ( pats) => {
371
- let witness = match & pats[ ..] {
372
- [ ref witness] => & * * witness,
373
- [ ] => DUMMY_WILD_PAT ,
374
- _ => unreachable ! ( )
371
+ let witnesses = match & pats[ ..] {
372
+ [ ] => vec ! [ DUMMY_WILD_PAT ] ,
373
+ [ p..] => {
374
+ p. iter ( ) . map ( |w| & * * w ) . collect ( )
375
+ }
375
376
} ;
376
377
match source {
377
378
hir:: MatchSource :: ForLoopDesugar => {
378
- // `witness ` has the form `Some(<head>)`, peel off the `Some`
379
- let witness = match witness . node {
379
+ // `witnesses[0] ` has the form `Some(<head>)`, peel off the `Some`
380
+ let witness = match witnesses [ 0 ] . node {
380
381
hir:: PatEnum ( _, Some ( ref pats) ) => match & pats[ ..] {
381
382
[ ref pat] => & * * pat,
382
383
_ => unreachable ! ( ) ,
383
384
} ,
384
385
_ => unreachable ! ( ) ,
385
386
} ;
386
-
387
387
span_err ! ( cx. tcx. sess, sp, E0297 ,
388
388
"refutable pattern in `for` loop binding: \
389
389
`{}` not covered",
390
390
pat_to_string( witness) ) ;
391
391
} ,
392
392
_ => {
393
+ let pattern_strings: Vec < _ > = witnesses. iter ( ) . map ( |w| {
394
+ pat_to_string ( w)
395
+ } ) . take ( 10 ) . collect ( ) ;
393
396
span_err ! ( cx. tcx. sess, sp, E0004 ,
394
397
"non-exhaustive patterns: `{}` not covered" ,
395
- pat_to_string ( witness )
398
+ pattern_strings . join ( "`, `" )
396
399
) ;
397
400
} ,
398
401
}
@@ -594,14 +597,14 @@ impl<'tcx, 'container> ty::AdtDefData<'tcx, 'container> {
594
597
}
595
598
}
596
599
597
- fn missing_constructor ( cx : & MatchCheckCtxt , & Matrix ( ref rows) : & Matrix ,
598
- left_ty : Ty , max_slice_length : usize ) -> Option < Constructor > {
600
+ fn missing_constructors ( cx : & MatchCheckCtxt , & Matrix ( ref rows) : & Matrix ,
601
+ left_ty : Ty , max_slice_length : usize ) -> Vec < Constructor > {
599
602
let used_constructors: Vec < Constructor > = rows. iter ( )
600
603
. flat_map ( |row| pat_constructors ( cx, row[ 0 ] , left_ty, max_slice_length) )
601
604
. collect ( ) ;
602
605
all_constructors ( cx, left_ty, max_slice_length)
603
606
. into_iter ( )
604
- . find ( |c| !used_constructors. contains ( c) )
607
+ . filter ( |c| !used_constructors. contains ( c) ) . collect ( )
605
608
}
606
609
607
610
/// This determines the set of all possible constructors of a pattern matching
@@ -680,8 +683,8 @@ fn is_useful(cx: &MatchCheckCtxt,
680
683
681
684
let constructors = pat_constructors ( cx, v[ 0 ] , left_ty, max_slice_length) ;
682
685
if constructors. is_empty ( ) {
683
- match missing_constructor ( cx, matrix, left_ty, max_slice_length) {
684
- None => {
686
+ match & missing_constructors ( cx, matrix, left_ty, max_slice_length) [ .. ] {
687
+ [ ] => {
685
688
all_constructors ( cx, left_ty, max_slice_length) . into_iter ( ) . map ( |c| {
686
689
match is_useful_specialized ( cx, matrix, v, c. clone ( ) , left_ty, witness) {
687
690
UsefulWithWitness ( pats) => UsefulWithWitness ( {
@@ -701,7 +704,7 @@ fn is_useful(cx: &MatchCheckCtxt,
701
704
} ) . find ( |result| result != & NotUseful ) . unwrap_or ( NotUseful )
702
705
} ,
703
706
704
- Some ( constructor ) => {
707
+ [ constructors.. ] => {
705
708
let matrix = rows. iter ( ) . filter_map ( |r| {
706
709
if pat_is_binding_or_wild ( & cx. tcx . def_map . borrow ( ) , raw_pat ( r[ 0 ] ) ) {
707
710
Some ( r[ 1 ..] . to_vec ( ) )
@@ -711,10 +714,11 @@ fn is_useful(cx: &MatchCheckCtxt,
711
714
} ) . collect ( ) ;
712
715
match is_useful ( cx, & matrix, & v[ 1 ..] , witness) {
713
716
UsefulWithWitness ( pats) => {
714
- let arity = constructor_arity ( cx, & constructor, left_ty) ;
715
- let wild_pats = vec ! [ DUMMY_WILD_PAT ; arity] ;
716
- let enum_pat = construct_witness ( cx, & constructor, wild_pats, left_ty) ;
717
- let mut new_pats = vec ! [ enum_pat] ;
717
+ let mut new_pats: Vec < _ > = constructors. into_iter ( ) . map ( |constructor| {
718
+ let arity = constructor_arity ( cx, & constructor, left_ty) ;
719
+ let wild_pats = vec ! [ DUMMY_WILD_PAT ; arity] ;
720
+ construct_witness ( cx, & constructor, wild_pats, left_ty)
721
+ } ) . collect ( ) ;
718
722
new_pats. extend ( pats) ;
719
723
UsefulWithWitness ( new_pats)
720
724
} ,
0 commit comments