@@ -331,6 +331,14 @@ impl Constructor {
331
331
}
332
332
}
333
333
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
+
334
342
fn variant_id_for_adt ( & self , adt : hir_def:: AdtId ) -> VariantId {
335
343
match * self {
336
344
Variant ( id) => id. into ( ) ,
@@ -555,32 +563,33 @@ impl SplitWildcard {
555
563
// witness.
556
564
let is_declared_nonexhaustive = cx. is_foreign_non_exhaustive_enum ( pcx. ty ) ;
557
565
566
+ let is_exhaustive_pat_feature = cx. feature_exhaustive_patterns ( ) ;
567
+
558
568
// If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
559
569
// as though it had an "unknown" constructor to avoid exposing its emptiness. The
560
570
// exception is if the pattern is at the top level, because we want empty matches to be
561
571
// considered exhaustive.
562
572
let is_secretly_empty = enum_data. variants . is_empty ( )
563
- && !cx . feature_exhaustive_patterns ( )
573
+ && !is_exhaustive_pat_feature
564
574
&& !pcx. is_top_level ;
565
575
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 ) ;
583
591
}
592
+ ctors
584
593
}
585
594
TyKind :: Scalar ( Scalar :: Char ) => unhandled ( ) ,
586
595
TyKind :: Scalar ( Scalar :: Int ( ..) | Scalar :: Uint ( ..) ) => unhandled ( ) ,
@@ -660,9 +669,7 @@ impl SplitWildcard {
660
669
Missing {
661
670
nonexhaustive_enum_missing_real_variants : self
662
671
. 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) ) ) ,
666
673
}
667
674
} else {
668
675
Missing { nonexhaustive_enum_missing_real_variants : false }
@@ -819,9 +826,9 @@ impl<'p> Fields<'p> {
819
826
820
827
/// Values and patterns can be represented as a constructor applied to some fields. This represents
821
828
/// 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
823
830
/// 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.
825
832
pub ( crate ) struct DeconstructedPat < ' p > {
826
833
ctor : Constructor ,
827
834
fields : Fields < ' p > ,
0 commit comments