Skip to content

Commit 4390987

Browse files
committed
explain split better
1 parent 0da9d3e commit 4390987

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,13 +941,28 @@ impl ConstructorSet {
941941
}
942942
}
943943

944-
/// Split the set into two vecs `split` and `missing`, respecting the following:
944+
/// This is the core logical operation of exhaustiveness checking.
945+
/// Given a set of patterns in a match, we look at their head constructors and ask the
946+
/// questions: which constructors are present in the match, and which are missing.
947+
/// For this we first need to know about the full set of constructors for this type, which is
948+
/// represented by this `ConstructorSet`. We then construct two lists of constructors.
949+
///
950+
/// Formally, this returns two vecs `split` and `missing`, respecting the following constraints:
945951
/// - `split` covers the whole type
946-
/// - constructors in `split` and `missing` are split for the `ctors` list
947-
/// - all non-wildcards in `ctors` cover something in `split` (including `Opaques`)
948-
/// - no non-wildcard in `ctors` covers anything in `missing`
949-
/// - if we replace any `Wildcard`/`Missing` in `split` with all of `missing`, this also
952+
/// - `split` is made of:
953+
/// - at most one wildcard (`Wildcard` or `Missing`)
954+
/// - non-wildcard constructors that are each covered by some non-wildcard constructor in `ctors`
955+
/// - together, the non-wildcard constructors in `split` cover all the non-wildcard
956+
/// constructor in `ctors`, including `Opaques`
957+
/// - non-wildcards in `ctors` do no cover anything in `missing`
958+
/// - if we replace the `Wildcard`/`Missing` in `split` with all of `missing`, this also
950959
/// covers the whole type
960+
/// - constructors in `split` and `missing` are split for the `ctors` list; in other words,
961+
/// they are either fully included in or disjoint from each constructor in `ctors`
962+
///
963+
/// Note in particular that wildcards in `ctors` are irrelevant; they do not change which
964+
/// constructors are present.
965+
/// FIXME(Nadrieril): examples?
951966
pub(super) fn split<'a, 'tcx>(
952967
&self,
953968
pcx: &PatCtxt<'_, '_, 'tcx>,

0 commit comments

Comments
 (0)