pub(crate) struct WitnessStack<'tcx>(Vec<WitnessPat<'tcx>>);
Expand description

A witness-tuple of non-exhaustiveness for error reporting, represented as a list of patterns (in reverse order of construction) with wildcards inside to represent elements that can take any inhabitant of the type as a value.

This mirrors PatStack: they function similarly, except PatStack contains user patterns we are inspecting, and WitnessStack contains witnesses we are constructing. FIXME(Nadrieril): use the same order of patterns for both

A WitnessStack should have the same types and length as the PatStacks we are inspecting (except we store the patterns in reverse order). Because Rust match is always against a single pattern, at the end the stack will have length 1. In the middle of the algorithm, it can contain multiple patterns.

For example, if we are constructing a witness for the match against

ⓘ
struct Pair(Option<(u32, u32)>, bool);
match p {
   Pair(None, _) => {}
   Pair(_, false) => {}
}

We’ll perform the following steps (among others):

  • Start with a matrix representing the match PatStack(vec![Pair(None, _)]) PatStack(vec![Pair(_, false)])
  • Specialize with Pair PatStack(vec![None, _]) PatStack(vec![_, false])
  • Specialize with Some PatStack(vec![_, false])
  • Specialize with _ PatStack(vec![false])
  • Specialize with true // no patstacks left
  • This is a non-exhaustive match: we have the empty witness stack as a witness. WitnessStack(vec![])
  • Apply true WitnessStack(vec![true])
  • Apply _ WitnessStack(vec![true, _])
  • Apply Some WitnessStack(vec![true, Some(_)])
  • Apply Pair WitnessStack(vec![Pair(Some(_), true)])

The final Pair(Some(_), true) is then the resulting witness.

Tuple Fields§

§0: Vec<WitnessPat<'tcx>>

Implementations§

source§

impl<'tcx> WitnessStack<'tcx>

source

fn single_pattern(self) -> WitnessPat<'tcx>

Asserts that the witness contains a single pattern, and returns it.

source

fn apply_constructor( self, pcx: &PatCtxt<'_, '_, 'tcx>, ctor: &Constructor<'tcx> ) -> Self

Constructs a partial witness for a pattern given a list of patterns expanded by the specialization step.

When a pattern P is discovered to be useful, this function is used bottom-up to reconstruct a complete witness, e.g., a pattern P’ that covers a subset of values, V, where each value in that set is not covered by any previously used patterns and is covered by the pattern P’. Examples:

left_ty: tuple of 3 elements pats: [10, 20, _] => (10, 20, _)

left_ty: struct X { a: (bool, &’static str), b: usize} pats: [(false, “foo”), 42] => X { a: (false, “foo”), b: 42 }

Trait Implementations§

source§

impl<'tcx> Clone for WitnessStack<'tcx>

source§

fn clone(&self) -> WitnessStack<'tcx>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'tcx> Debug for WitnessStack<'tcx>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'tcx> !RefUnwindSafe for WitnessStack<'tcx>

§

impl<'tcx> Send for WitnessStack<'tcx>

§

impl<'tcx> Sync for WitnessStack<'tcx>

§

impl<'tcx> Unpin for WitnessStack<'tcx>

§

impl<'tcx> !UnwindSafe for WitnessStack<'tcx>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes