@@ -618,10 +618,15 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
618
618
let new_witnesses = if let Constructor :: Missing { .. } = ctor {
619
619
// We got the special `Missing` constructor, so each of the missing constructors
620
620
// gives a new pattern that is not caught by the match. We list those patterns.
621
- let new_patterns = if pcx. is_non_exhaustive {
622
- // Here we don't want the user to try to list all variants, we want them to add
623
- // a wildcard, so we only suggest that.
624
- vec ! [ DeconstructedPat :: wildcard( pcx. ty, pcx. span) ]
621
+ if pcx. is_non_exhaustive {
622
+ witnesses
623
+ . into_iter ( )
624
+ // Here we don't want the user to try to list all variants, we want them to add
625
+ // a wildcard, so we only suggest that.
626
+ . map ( |witness| {
627
+ witness. apply_constructor ( pcx, & Constructor :: NonExhaustive )
628
+ } )
629
+ . collect ( )
625
630
} else {
626
631
let mut split_wildcard = SplitWildcard :: new ( pcx) ;
627
632
split_wildcard. split ( pcx, matrix. heads ( ) . map ( DeconstructedPat :: ctor) ) ;
@@ -633,7 +638,7 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
633
638
// constructor, that matches everything that can be built with
634
639
// it. For example, if `ctor` is a `Constructor::Variant` for
635
640
// `Option::Some`, we get the pattern `Some(_)`.
636
- let mut new : Vec < DeconstructedPat < ' _ , ' _ > > = split_wildcard
641
+ let mut new_patterns : Vec < DeconstructedPat < ' _ , ' _ > > = split_wildcard
637
642
. iter_missing ( pcx)
638
643
. filter_map ( |missing_ctor| {
639
644
// Check if this variant is marked `doc(hidden)`
@@ -648,27 +653,25 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
648
653
. collect ( ) ;
649
654
650
655
if hide_variant_show_wild {
651
- new . push ( DeconstructedPat :: wildcard ( pcx. ty , pcx. span ) ) ;
656
+ new_patterns . push ( DeconstructedPat :: wildcard ( pcx. ty , pcx. span ) ) ;
652
657
}
653
658
654
- new
655
- } ;
656
-
657
- witnesses
658
- . into_iter ( )
659
- . flat_map ( |witness| {
660
- new_patterns. iter ( ) . map ( move |pat| {
661
- Witness (
662
- witness
663
- . 0
664
- . iter ( )
665
- . chain ( once ( pat) )
666
- . map ( DeconstructedPat :: clone_and_forget_reachability)
667
- . collect ( ) ,
668
- )
659
+ witnesses
660
+ . into_iter ( )
661
+ . flat_map ( |witness| {
662
+ new_patterns. iter ( ) . map ( move |pat| {
663
+ Witness (
664
+ witness
665
+ . 0
666
+ . iter ( )
667
+ . chain ( once ( pat) )
668
+ . map ( DeconstructedPat :: clone_and_forget_reachability)
669
+ . collect ( ) ,
670
+ )
671
+ } )
669
672
} )
670
- } )
671
- . collect ( )
673
+ . collect ( )
674
+ }
672
675
} else {
673
676
witnesses
674
677
. into_iter ( )
0 commit comments