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
Expand description
The empty set. This means the pattern is unreachable.
Expand description
The set containing the full pattern.
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.
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
Implementations
impl<'p, 'tcx> SubPatSet<'p, 'tcx>[src]
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 list_unreachable_spans(&self) -> Option<Vec<Span>>[src]
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]
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]
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
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> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
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]
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<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,