Enum rustc_mir_build::thir::pattern::usefulness::SubPatSet [−][src]
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
The empty set. This means the pattern is unreachable.
The set containing the full pattern.
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.
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
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]
self,
alt_id: usize,
alt_count: usize,
pat: &'p Pat<'tcx>
) -> Self
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
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,
'tcx: 'p,
impl<'p, 'tcx> !UnwindSafe for SubPatSet<'p, 'tcx>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,