Function rustc_mir::hair::pattern::_match::is_useful[][src]

pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(
    cx: &mut MatchCheckCtxt<'a, 'tcx>,
    matrix: &Matrix<'p, 'tcx>,
    v: &[&'p Pattern<'tcx>],
    witness: WitnessPreference
) -> Usefulness<'tcx>
🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

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. eg. 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, except that wildcard (PatternKind::Wild) patterns with type TyErr are also allowed, even if the "type of the column" is not TyErr. That is used to represent private fields, as using their real type would assert that they are inhabited.

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).