fn is_useful<'p, 'tcx>(
    cx: &MatchCheckCtxt<'p, 'tcx>,
    matrix: &Matrix<'p, 'tcx>,
    v: &PatStack<'p, 'tcx>,
    witness_preference: ArmType,
    lint_root: HirId,
    is_under_guard: bool,
    is_top_level: bool
) -> Usefulness<'p, 'tcx>
Expand description

Algorithm from http://moscova.inria.fr/~maranget/papers/warn/index.html. The algorithm from the paper has been modified to correctly handle empty types. The changes are: (0) We don’t exit early if the pattern matrix has zero rows. We just continue to recurse over columns. (1) all_constructors will only return constructors that are statically possible. E.g., it will only return Ok for Result<T, !>.

This finds whether a (row) vector v of patterns is ‘useful’ in relation to a set of such vectors m - this is defined as there being a set of inputs that will match v but not any of the sets in m.

All the patterns at each column of the matrix ++ v matrix must have the same type.

This is used both for reachability checking (if a pattern isn’t useful in relation to preceding patterns, it is not reachable) and exhaustiveness checking (if a wildcard pattern is useful in relation to a matrix, the matrix isn’t exhaustive).

is_under_guard is used to inform if the pattern has a guard. If it has one it must not be inserted into the matrix. This shouldn’t be relied on for soundness.