@@ -796,6 +796,9 @@ fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
796
796
/// For example, the pattern `-128...127i8` is encoded as `0..=255`.
797
797
/// This makes comparisons and arithmetic on interval endpoints much more
798
798
/// straightforward. See `signed_bias` for details.
799
+ ///
800
+ /// `IntRange` is never used to encode an empty range or a "range" that wraps
801
+ /// around the (offset) space: i.e. `range.lo <= range.hi`.
799
802
struct IntRange < ' tcx > {
800
803
pub range : RangeInclusive < u128 > ,
801
804
pub ty : Ty < ' tcx > ,
@@ -882,10 +885,8 @@ impl<'tcx> IntRange<'tcx> {
882
885
}
883
886
}
884
887
885
- /// Given an `IntRange` corresponding to a pattern in a `match` and a collection of
886
- /// ranges corresponding to the domain of values of a type (say, an integer), return
887
- /// a new collection of ranges corresponding to the original ranges minus the ranges
888
- /// covered by the `IntRange`.
888
+ /// Return a collection of ranges that spans the values covered by `ranges`, subtracted
889
+ /// by the values covered by `self`: i.e. `ranges \ self` (in set notation).
889
890
fn subtract_from ( self ,
890
891
tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
891
892
ranges : Vec < Constructor < ' tcx > > )
@@ -930,7 +931,7 @@ impl<'tcx> IntRange<'tcx> {
930
931
}
931
932
}
932
933
933
- // Find those constructors that are not matched by any non-wildcard patterns in the current column .
934
+ // Return a set of constructors equivalent to `all_ctors \ used_ctors` .
934
935
fn compute_missing_ctors < ' a , ' tcx : ' a > (
935
936
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
936
937
all_ctors : & Vec < Constructor < ' tcx > > ,
@@ -1079,6 +1080,9 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
1079
1080
// be a privately-empty enum is when the exhaustive_patterns
1080
1081
// feature flag is not present, so this is only
1081
1082
// needed for that case.
1083
+
1084
+ // Find those constructors that are not matched by any non-wildcard patterns in the
1085
+ // current column.
1082
1086
let missing_ctors = compute_missing_ctors ( cx. tcx , & all_ctors, & used_ctors) ;
1083
1087
1084
1088
let is_privately_empty = all_ctors. is_empty ( ) && !cx. is_uninhabited ( pcx. ty ) ;
0 commit comments