@@ -796,6 +796,9 @@ fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
796796/// For example, the pattern `-128...127i8` is encoded as `0..=255`.
797797/// This makes comparisons and arithmetic on interval endpoints much more
798798/// 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`.
799802struct IntRange < ' tcx > {
800803 pub range : RangeInclusive < u128 > ,
801804 pub ty : Ty < ' tcx > ,
@@ -882,10 +885,8 @@ impl<'tcx> IntRange<'tcx> {
882885 }
883886 }
884887
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).
889890 fn subtract_from ( self ,
890891 tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
891892 ranges : Vec < Constructor < ' tcx > > )
@@ -930,7 +931,7 @@ impl<'tcx> IntRange<'tcx> {
930931 }
931932}
932933
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` .
934935fn compute_missing_ctors < ' a , ' tcx : ' a > (
935936 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
936937 all_ctors : & Vec < Constructor < ' tcx > > ,
@@ -1079,6 +1080,9 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
10791080 // be a privately-empty enum is when the exhaustive_patterns
10801081 // feature flag is not present, so this is only
10811082 // needed for that case.
1083+
1084+ // Find those constructors that are not matched by any non-wildcard patterns in the
1085+ // current column.
10821086 let missing_ctors = compute_missing_ctors ( cx. tcx , & all_ctors, & used_ctors) ;
10831087
10841088 let is_privately_empty = all_ctors. is_empty ( ) && !cx. is_uninhabited ( pcx. ty ) ;
0 commit comments