@@ -331,6 +331,14 @@ impl Constructor {
331331 }
332332 }
333333
334+ pub ( super ) fn is_unstable_variant ( & self , _pcx : PatCtxt < ' _ , ' _ > ) -> bool {
335+ false //FIXME: implement this
336+ }
337+
338+ pub ( super ) fn is_doc_hidden_variant ( & self , _pcx : PatCtxt < ' _ , ' _ > ) -> bool {
339+ false //FIXME: implement this
340+ }
341+
334342 fn variant_id_for_adt ( & self , adt : hir_def:: AdtId ) -> VariantId {
335343 match * self {
336344 Variant ( id) => id. into ( ) ,
@@ -555,32 +563,33 @@ impl SplitWildcard {
555563 // witness.
556564 let is_declared_nonexhaustive = cx. is_foreign_non_exhaustive_enum ( pcx. ty ) ;
557565
566+ let is_exhaustive_pat_feature = cx. feature_exhaustive_patterns ( ) ;
567+
558568 // If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
559569 // as though it had an "unknown" constructor to avoid exposing its emptiness. The
560570 // exception is if the pattern is at the top level, because we want empty matches to be
561571 // considered exhaustive.
562572 let is_secretly_empty = enum_data. variants . is_empty ( )
563- && !cx . feature_exhaustive_patterns ( )
573+ && !is_exhaustive_pat_feature
564574 && !pcx. is_top_level ;
565575
566- if is_secretly_empty {
567- smallvec ! [ NonExhaustive ]
568- } else if is_declared_nonexhaustive {
569- enum_data
570- . variants
571- . iter ( )
572- . map ( |( local_id, ..) | Variant ( EnumVariantId { parent : enum_id, local_id } ) )
573- . chain ( Some ( NonExhaustive ) )
574- . collect ( )
575- } else if cx. feature_exhaustive_patterns ( ) {
576- unimplemented ! ( ) // see MatchCheckCtx.feature_exhaustive_patterns()
577- } else {
578- enum_data
579- . variants
580- . iter ( )
581- . map ( |( local_id, ..) | Variant ( EnumVariantId { parent : enum_id, local_id } ) )
582- . collect ( )
576+ let mut ctors: SmallVec < [ _ ; 1 ] > = enum_data
577+ . variants
578+ . iter ( )
579+ . filter ( |& ( _, _v) | {
580+ // If `exhaustive_patterns` is enabled, we exclude variants known to be
581+ // uninhabited.
582+ let is_uninhabited = is_exhaustive_pat_feature
583+ && unimplemented ! ( "after MatchCheckCtx.feature_exhaustive_patterns()" ) ;
584+ !is_uninhabited
585+ } )
586+ . map ( |( local_id, _) | Variant ( EnumVariantId { parent : enum_id, local_id } ) )
587+ . collect ( ) ;
588+
589+ if is_secretly_empty || is_declared_nonexhaustive {
590+ ctors. push ( NonExhaustive ) ;
583591 }
592+ ctors
584593 }
585594 TyKind :: Scalar ( Scalar :: Char ) => unhandled ( ) ,
586595 TyKind :: Scalar ( Scalar :: Int ( ..) | Scalar :: Uint ( ..) ) => unhandled ( ) ,
@@ -660,9 +669,7 @@ impl SplitWildcard {
660669 Missing {
661670 nonexhaustive_enum_missing_real_variants : self
662671 . iter_missing ( pcx)
663- . filter ( |c| !c. is_non_exhaustive ( ) )
664- . next ( )
665- . is_some ( ) ,
672+ . any ( |c| !( c. is_non_exhaustive ( ) || c. is_unstable_variant ( pcx) ) ) ,
666673 }
667674 } else {
668675 Missing { nonexhaustive_enum_missing_real_variants : false }
@@ -819,9 +826,9 @@ impl<'p> Fields<'p> {
819826
820827/// Values and patterns can be represented as a constructor applied to some fields. This represents
821828/// a pattern in this form.
822- /// This also keeps track of whether the pattern has been foundreachable during analysis. For this
829+ /// This also keeps track of whether the pattern has been found reachable during analysis. For this
823830/// reason we should be careful not to clone patterns for which we care about that. Use
824- /// `clone_and_forget_reachability` is you're sure.
831+ /// `clone_and_forget_reachability` if you're sure.
825832pub ( crate ) struct DeconstructedPat < ' p > {
826833 ctor : Constructor ,
827834 fields : Fields < ' p > ,
0 commit comments