[−][src]Struct rustc_mir_build::thir::pattern::_match::Witness
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
Some(_)against theNoneWitness(vec![Some(_)]) - Push a witness
trueagainst thefalseWitness(vec![Some(_), true]) - Apply the
Pairconstructor to the witnessesWitness(vec![Pair(Some(_), true)])
The final Pair(Some(_), true) is then the resulting witness.
Implementations
impl<'tcx> Witness<'tcx>[src]
pub(in thir::pattern::_match) fn single_pattern(
self
) -> Pat<'tcx>[src]
self
) -> Pat<'tcx>
Asserts that the witness contains a single pattern, and returns it.
pub(in thir::pattern::_match) fn apply_constructor<'p>(
self,
pcx: PatCtxt<'_, 'p, 'tcx>,
ctor: &Constructor<'tcx>,
ctor_wild_subpatterns: &Fields<'p, 'tcx>
) -> Self[src]
self,
pcx: PatCtxt<'_, 'p, 'tcx>,
ctor: &Constructor<'tcx>,
ctor_wild_subpatterns: &Fields<'p, '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<'tcx> !RefUnwindSafe for Witness<'tcx>
impl<'tcx> !Send for Witness<'tcx>
impl<'tcx> !Sync for Witness<'tcx>
impl<'tcx> Unpin for Witness<'tcx>
impl<'tcx> !UnwindSafe for Witness<'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>,