@@ -332,6 +332,14 @@ impl Constructor {
332
332
}
333
333
}
334
334
335
+ pub ( super ) fn is_unstable_variant ( & self , _pcx : PatCtxt < ' _ , ' _ > ) -> bool {
336
+ false //FIXME: implement this
337
+ }
338
+
339
+ pub ( super ) fn is_doc_hidden_variant ( & self , _pcx : PatCtxt < ' _ , ' _ > ) -> bool {
340
+ false //FIXME: implement this
341
+ }
342
+
335
343
fn variant_id_for_adt ( & self , adt : hir_def:: AdtId ) -> VariantId {
336
344
match * self {
337
345
Variant ( id) => id. into ( ) ,
@@ -556,32 +564,33 @@ impl SplitWildcard {
556
564
// witness.
557
565
let is_declared_nonexhaustive = cx. is_foreign_non_exhaustive_enum ( pcx. ty ) ;
558
566
567
+ let is_exhaustive_pat_feature = cx. feature_exhaustive_patterns ( ) ;
568
+
559
569
// If `exhaustive_patterns` is disabled and our scrutinee is an empty enum, we treat it
560
570
// as though it had an "unknown" constructor to avoid exposing its emptiness. The
561
571
// exception is if the pattern is at the top level, because we want empty matches to be
562
572
// considered exhaustive.
563
573
let is_secretly_empty = enum_data. variants . is_empty ( )
564
- && !cx . feature_exhaustive_patterns ( )
574
+ && !is_exhaustive_pat_feature
565
575
&& !pcx. is_top_level ;
566
576
567
- if is_secretly_empty {
568
- smallvec ! [ NonExhaustive ]
569
- } else if is_declared_nonexhaustive {
570
- enum_data
571
- . variants
572
- . iter ( )
573
- . map ( |( local_id, ..) | Variant ( EnumVariantId { parent : enum_id, local_id } ) )
574
- . chain ( Some ( NonExhaustive ) )
575
- . collect ( )
576
- } else if cx. feature_exhaustive_patterns ( ) {
577
- unimplemented ! ( ) // see MatchCheckCtx.feature_exhaustive_patterns()
578
- } else {
579
- enum_data
580
- . variants
581
- . iter ( )
582
- . map ( |( local_id, ..) | Variant ( EnumVariantId { parent : enum_id, local_id } ) )
583
- . collect ( )
577
+ let mut ctors: SmallVec < [ _ ; 1 ] > = enum_data
578
+ . variants
579
+ . iter ( )
580
+ . filter ( |& ( _, _v) | {
581
+ // If `exhaustive_patterns` is enabled, we exclude variants known to be
582
+ // uninhabited.
583
+ let is_uninhabited = is_exhaustive_pat_feature
584
+ && unimplemented ! ( "after MatchCheckCtx.feature_exhaustive_patterns()" ) ;
585
+ !is_uninhabited
586
+ } )
587
+ . map ( |( local_id, _) | Variant ( EnumVariantId { parent : enum_id, local_id } ) )
588
+ . collect ( ) ;
589
+
590
+ if is_secretly_empty || is_declared_nonexhaustive {
591
+ ctors. push ( NonExhaustive ) ;
584
592
}
593
+ ctors
585
594
}
586
595
TyKind :: Scalar ( Scalar :: Char ) => unhandled ( ) ,
587
596
TyKind :: Scalar ( Scalar :: Int ( ..) | Scalar :: Uint ( ..) ) => unhandled ( ) ,
@@ -661,9 +670,7 @@ impl SplitWildcard {
661
670
Missing {
662
671
nonexhaustive_enum_missing_real_variants : self
663
672
. iter_missing ( pcx)
664
- . filter ( |c| !c. is_non_exhaustive ( ) )
665
- . next ( )
666
- . is_some ( ) ,
673
+ . any ( |c| !( c. is_non_exhaustive ( ) || c. is_unstable_variant ( pcx) ) ) ,
667
674
}
668
675
} else {
669
676
Missing { nonexhaustive_enum_missing_real_variants : false }
@@ -820,9 +827,9 @@ impl<'p> Fields<'p> {
820
827
821
828
/// Values and patterns can be represented as a constructor applied to some fields. This represents
822
829
/// a pattern in this form.
823
- /// This also keeps track of whether the pattern has been foundreachable during analysis. For this
830
+ /// This also keeps track of whether the pattern has been found reachable during analysis. For this
824
831
/// reason we should be careful not to clone patterns for which we care about that. Use
825
- /// `clone_and_forget_reachability` is you're sure.
832
+ /// `clone_and_forget_reachability` if you're sure.
826
833
pub ( crate ) struct DeconstructedPat < ' p > {
827
834
ctor : Constructor ,
828
835
fields : Fields < ' p > ,
0 commit comments