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>,
    },
}
Expand description

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
Expand description

The empty set. This means the pattern is unreachable.

Full
Expand description

The set containing the full pattern.

Seq
Expand description

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.

Show fields

Fields of Seq

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

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.

Show fields

Fields of Alt

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

Counts the total number of alternatives in the pattern

pat: &'p Pat<'tcx>
Expand description

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]

fn clone(&self) -> SubPatSet<'p, 'tcx>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

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