Struct rustc_pattern_analysis::usefulness::WitnessStack
source · struct WitnessStack<Cx: TypeCx>(Vec<WitnessPat<Cx>>);Expand description
A witness-tuple of non-exhaustiveness for error reporting, represented as a list of patterns (in reverse order of construction).
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). The same way PatStack starts with length 1,
at the end of the algorithm this 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.
See the top of the file for more detailed explanations and examples.
Tuple Fields§
§0: Vec<WitnessPat<Cx>>Implementations§
source§impl<Cx: TypeCx> WitnessStack<Cx>
impl<Cx: TypeCx> WitnessStack<Cx>
sourcefn single_pattern(self) -> WitnessPat<Cx>
fn single_pattern(self) -> WitnessPat<Cx>
Asserts that the witness contains a single pattern, and returns it.
sourcefn push_pattern(&mut self, pat: WitnessPat<Cx>)
fn push_pattern(&mut self, pat: WitnessPat<Cx>)
Reverses specialization by the Missing constructor by pushing a whole new pattern.
sourcefn apply_constructor(
&mut self,
pcx: &PlaceCtxt<'_, '_, Cx>,
ctor: &Constructor<Cx>
)
fn apply_constructor( &mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx> )
Reverses specialization. Given a witness obtained after specialization, this constructs a
new witness valid for before specialization. See the section on unspecialize at the top of
the file.
Examples:
ctor: tuple of 2 elements
pats: [false, "foo", _, true]
result: [(false, "foo"), _, true]
ctor: Enum::Variant { a: (bool, &'static str), b: usize}
pats: [(false, "foo"), _, true]
result: [Enum::Variant { a: (false, "foo"), b: _ }, true]
Trait Implementations§
source§impl<Cx: TypeCx> Clone for WitnessStack<Cx>
impl<Cx: TypeCx> Clone for WitnessStack<Cx>
Auto Trait Implementations§
impl<Cx> RefUnwindSafe for WitnessStack<Cx>where
<Cx as TypeCx>::StrLit: RefUnwindSafe,
<Cx as TypeCx>::Ty: RefUnwindSafe,
<Cx as TypeCx>::VariantIdx: RefUnwindSafe,
impl<Cx> Send for WitnessStack<Cx>
impl<Cx> Sync for WitnessStack<Cx>
impl<Cx> Unpin for WitnessStack<Cx>
impl<Cx> UnwindSafe for WitnessStack<Cx>where
<Cx as TypeCx>::StrLit: UnwindSafe,
<Cx as TypeCx>::Ty: UnwindSafe,
<Cx as TypeCx>::VariantIdx: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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