Struct rustc_mir_build::thir::pattern::usefulness::Witness
source · pub(crate) struct Witness<'p, 'tcx>(Vec<DeconstructedPat<'p, 'tcx>>);
Expand description
A witness 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.
A witness against a list of patterns should have the same types
and length as the pattern matched against. Because Rust match
is always against a single pattern, at the end the witness will
have length 1, but 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) {
Pair(None, _) => {}
Pair(_, false) => {}
}
We’ll perform the following steps:
- Start with an empty witness
Witness(vec![])
- Push a witness
true
against thefalse
Witness(vec![true])
- Push a witness
Some(_)
against theNone
Witness(vec![true, Some(_)])
- Apply the
Pair
constructor to the witnessesWitness(vec![Pair(Some(_), true)])
The final Pair(Some(_), true)
is then the resulting witness.
Tuple Fields
0: Vec<DeconstructedPat<'p, 'tcx>>
Implementations
sourceimpl<'p, 'tcx> Witness<'p, 'tcx>
impl<'p, 'tcx> Witness<'p, 'tcx>
sourcefn single_pattern(self) -> DeconstructedPat<'p, 'tcx>
fn single_pattern(self) -> DeconstructedPat<'p, 'tcx>
Asserts that the witness contains a single pattern, and returns it.
sourcefn apply_constructor(
self,
pcx: &PatCtxt<'_, 'p, 'tcx>,
ctor: &Constructor<'tcx>
) -> Self
fn apply_constructor(
self,
pcx: &PatCtxt<'_, 'p, '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
Auto Trait Implementations
impl<'p, 'tcx> !RefUnwindSafe for Witness<'p, 'tcx>
impl<'p, 'tcx> !Send for Witness<'p, 'tcx>
impl<'p, 'tcx> !Sync for Witness<'p, 'tcx>
impl<'p, 'tcx> Unpin for Witness<'p, 'tcx>where
'tcx: 'p,
impl<'p, 'tcx> !UnwindSafe for Witness<'p, 'tcx>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn 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