@@ -799,11 +799,9 @@ enum Constructor<'tcx> {
799
799
/// boxes for the purposes of exhaustiveness: we must not inspect them, and they
800
800
/// don't count towards making a match exhaustive.
801
801
Opaque,
802
- /// Fake extra constructor for enums that aren't allowed to be matched exhaustively.
802
+ /// Fake extra constructor for enums that aren't allowed to be matched exhaustively. Also used
803
+ /// for those types for which we cannot list constructors explicitly, like `f64` and `str`.
803
804
NonExhaustive,
804
- /// Fake constructor for those types for which we can't list constructors explicitly, like
805
- /// `f64` and `str`.
806
- Unlistable,
807
805
/// Wildcard pattern.
808
806
Wildcard,
809
807
}
@@ -897,6 +895,7 @@ impl<'tcx> Constructor<'tcx> {
897
895
/// For the simple cases, this is simply checking for equality. For the "grouped" constructors,
898
896
/// this checks for inclusion.
899
897
fn is_covered_by<'p>(&self, pcx: PatCtxt<'_, 'p, 'tcx>, other: &Self) -> bool {
898
+ // This must be kept in sync with `is_covered_by_any`.
900
899
match (self, other) {
901
900
// Wildcards cover anything
902
901
(_, Wildcard) => true,
@@ -939,11 +938,6 @@ impl<'tcx> Constructor<'tcx> {
939
938
(Opaque, _) | (_, Opaque) => false,
940
939
// Only a wildcard pattern can match the special extra constructor.
941
940
(NonExhaustive, _) => false,
942
- // If we encounter a `Single` here, this means there was only one constructor for this
943
- // type after all.
944
- (Unlistable, Single) => true,
945
- // Otherwise, only a wildcard pattern can match the special extra constructor.
946
- (Unlistable, _) => false,
947
941
948
942
_ => span_bug!(
949
943
pcx.span,
@@ -955,7 +949,8 @@ impl<'tcx> Constructor<'tcx> {
955
949
}
956
950
957
951
/// Faster version of `is_covered_by` when applied to many constructors. `used_ctors` is
958
- /// assumed to be built from `matrix.head_ctors()`, and `self` is assumed to have been split.
952
+ /// assumed to be built from `matrix.head_ctors()` with wildcards filtered out, and `self` is
953
+ /// assumed to have been split from a wildcard.
959
954
fn is_covered_by_any<'p>(
960
955
&self,
961
956
pcx: PatCtxt<'_, 'p, 'tcx>,
@@ -965,8 +960,9 @@ impl<'tcx> Constructor<'tcx> {
965
960
return false;
966
961
}
967
962
963
+ // This must be kept in sync with `is_covered_by`.
968
964
match self {
969
- // `used_ctors` cannot contain anything else than `Single`s.
965
+ // If `self` is `Single`, `used_ctors` cannot contain anything else than `Single`s.
970
966
Single => !used_ctors.is_empty(),
971
967
Variant(_) => used_ctors.iter().any(|c| c == self),
972
968
IntRange(range) => used_ctors
@@ -979,8 +975,6 @@ impl<'tcx> Constructor<'tcx> {
979
975
.any(|other| slice.is_covered_by(other)),
980
976
// This constructor is never covered by anything else
981
977
NonExhaustive => false,
982
- // This constructor is only covered by `Single`s
983
- Unlistable => used_ctors.iter().any(|c| *c == Single),
984
978
Str(..) | FloatRange(..) | Opaque | Wildcard => {
985
979
bug!("found unexpected ctor in all_ctors: {:?}", self)
986
980
}
@@ -1064,7 +1058,7 @@ impl<'tcx> Constructor<'tcx> {
1064
1058
&Str(value) => PatKind::Constant { value },
1065
1059
&FloatRange(lo, hi, end) => PatKind::Range(PatRange { lo, hi, end }),
1066
1060
IntRange(range) => return range.to_pat(pcx.cx.tcx),
1067
- NonExhaustive | Unlistable => PatKind::Wild,
1061
+ NonExhaustive => PatKind::Wild,
1068
1062
Opaque => bug!("we should not try to apply an opaque constructor"),
1069
1063
Wildcard => bug!(
1070
1064
"trying to apply a wildcard constructor; this should have been done in `apply_constructors`"
@@ -1213,8 +1207,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1213
1207
}
1214
1208
_ => bug!("bad slice pattern {:?} {:?}", constructor, ty),
1215
1209
},
1216
- Str(..) | FloatRange(..) | IntRange(..) | NonExhaustive | Opaque | Unlistable
1217
- | Wildcard => Fields::empty(),
1210
+ Str(..) | FloatRange(..) | IntRange(..) | NonExhaustive | Opaque | Wildcard => {
1211
+ Fields::empty()
1212
+ }
1218
1213
};
1219
1214
debug!("Fields::wildcards({:?}, {:?}) = {:#?}", constructor, ty, ret);
1220
1215
ret
@@ -1624,8 +1619,8 @@ fn all_constructors<'p, 'tcx>(pcx: PatCtxt<'_, 'p, 'tcx>) -> Vec<Constructor<'tc
1624
1619
}
1625
1620
_ if cx.is_uninhabited(pcx.ty) => vec![],
1626
1621
ty::Adt(..) | ty::Tuple(..) | ty::Ref(..) => vec![Single],
1627
- // This type is one for which we don't know how to list constructors, like `str` or `f64`.
1628
- _ => vec![Unlistable ],
1622
+ // This type is one for which we cannot list constructors, like `str` or `f64`.
1623
+ _ => vec![NonExhaustive ],
1629
1624
}
1630
1625
}
1631
1626
0 commit comments