Enum rustc_mir_build::thir::pattern::usefulness::SubPatSet[−][src]

enum SubPatSet<'p, 'tcx> {
    Empty,
    Full,
    Seq {
        subpats: FxHashMap<usize, SubPatSet<'p, 'tcx>>,
    },
    Alt {
        subpats: FxHashMap<usize, SubPatSet<'p, 'tcx>>,
        alt_count: usize,
        pat: &'p Pat<'tcx>,
    },
}

Given a pattern or a pattern-stack, this struct captures a set of its subpatterns. We use that to track reachable sub-patterns arising from or-patterns. In the absence of or-patterns this will always be either Empty (the whole pattern is unreachable) or Full (the whole pattern is reachable). When there are or-patterns, some subpatterns may be reachable while others aren’t. In this case the whole pattern still counts as reachable, but we will lint the unreachable subpatterns.

This supports a limited set of operations, so not all possible sets of subpatterns can be represented. That’s ok, we only want the ones that make sense for our usage.

What we’re doing is illustrated by this:

match (true, 0) {
    (true, 0) => {}
    (_, 1) => {}
    (true | false, 0 | 1) => {}
}

When we try the alternatives of the true | false or-pattern, the last 0 is reachable in the false alternative but not the true. So overall it is reachable. By contrast, the last 1 is not reachable in either alternative, so we want to signal this to the user. Therefore we take the union of sets of reachable patterns coming from different alternatives in order to figure out which subpatterns are overall reachable.

Invariant: we try to construct the smallest representation we can. In particular if self.is_empty() we ensure that self is Empty, and same with Full. This is not important for correctness currently.

Variants

Empty

The empty set. This means the pattern is unreachable.

Full

The set containing the full pattern.

Seq

If the pattern is a pattern with a constructor or a pattern-stack, we store a set for each of its subpatterns. Missing entries in the map are implicitly full, because that’s the common case.

Fields of Seq

subpats: FxHashMap<usize, SubPatSet<'p, 'tcx>>
Alt

If the pattern is an or-pattern, we store a set for each of its alternatives. Missing entries in the map are implicitly empty. Note: we always flatten nested or-patterns.

Fields of Alt

subpats: FxHashMap<usize, SubPatSet<'p, 'tcx>>alt_count: usize

Counts the total number of alternatives in the pattern

pat: &'p Pat<'tcx>

We keep the pattern around to retrieve spans.

Implementations

impl<'p, 'tcx> SubPatSet<'p, 'tcx>[src]

fn full() -> Self[src]

fn empty() -> Self[src]

fn is_empty(&self) -> bool[src]

fn is_full(&self) -> bool[src]

fn union(&mut self, other: Self)[src]

Union self with other, mutating self.

fn list_unreachable_spans(&self) -> Option<Vec<Span>>[src]

Returns a list of the spans of the unreachable subpatterns. If self is empty (i.e. the whole pattern is unreachable) we return None.

fn unspecialize(self, arity: usize) -> Self[src]

When self refers to a patstack that was obtained from specialization, after running unspecialize it will refer to the original patstack before specialization.

fn unsplit_or_pat(
    self,
    alt_id: usize,
    alt_count: usize,
    pat: &'p Pat<'tcx>
) -> Self
[src]

When self refers to a patstack that was obtained from splitting an or-pattern, after running unspecialize it will refer to the original patstack before splitting.

For example:

match Some(true) {
    Some(true) => {}
    None | Some(true | false) => {}
}

Here None would return the full set and Some(true | false) would return the set containing false. After unsplit_or_pat, we want the set to contain None and false. This is what this function does.

Trait Implementations

impl<'p, 'tcx> Clone for SubPatSet<'p, 'tcx>[src]

impl<'p, 'tcx> Debug for SubPatSet<'p, 'tcx>[src]

Auto Trait Implementations

impl<'p, 'tcx> !RefUnwindSafe for SubPatSet<'p, 'tcx>

impl<'p, 'tcx> !Send for SubPatSet<'p, 'tcx>

impl<'p, 'tcx> !Sync for SubPatSet<'p, 'tcx>

impl<'p, 'tcx> Unpin for SubPatSet<'p, 'tcx> where
    'tcx: 'p, 

impl<'p, 'tcx> !UnwindSafe for SubPatSet<'p, 'tcx>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<'a, T> Captures<'a> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone, 
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.