@@ -618,10 +618,15 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
618618 let new_witnesses = if let Constructor :: Missing { .. } = ctor {
619619 // We got the special `Missing` constructor, so each of the missing constructors
620620 // 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 ( )
625630 } else {
626631 let mut split_wildcard = SplitWildcard :: new ( pcx) ;
627632 split_wildcard. split ( pcx, matrix. heads ( ) . map ( DeconstructedPat :: ctor) ) ;
@@ -633,7 +638,7 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
633638 // constructor, that matches everything that can be built with
634639 // it. For example, if `ctor` is a `Constructor::Variant` for
635640 // `Option::Some`, we get the pattern `Some(_)`.
636- let mut new : Vec < DeconstructedPat < ' _ , ' _ > > = split_wildcard
641+ let mut new_patterns : Vec < DeconstructedPat < ' _ , ' _ > > = split_wildcard
637642 . iter_missing ( pcx)
638643 . filter_map ( |missing_ctor| {
639644 // Check if this variant is marked `doc(hidden)`
@@ -648,27 +653,25 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
648653 . collect ( ) ;
649654
650655 if hide_variant_show_wild {
651- new . push ( DeconstructedPat :: wildcard ( pcx. ty , pcx. span ) ) ;
656+ new_patterns . push ( DeconstructedPat :: wildcard ( pcx. ty , pcx. span ) ) ;
652657 }
653658
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+ } )
669672 } )
670- } )
671- . collect ( )
673+ . collect ( )
674+ }
672675 } else {
673676 witnesses
674677 . into_iter ( )
0 commit comments