pub fn consequent_match_pairs_under_assumption(&mut self,
                                                   match_pair: MatchPair<'tcx>,
                                                   test_kind: &TestKind<'tcx>,
                                                   test_outcome: usize)
                                                   -> Option<Vec<MatchPair<'tcx>>> {
        match match_pair.pattern.kind {
            PatternKind::Variant { adt_def, variant_index, subpatterns } => {
                assert!(match *test_kind { TestKind::Switch { .. } => true,
                                           _ => false });

                if test_outcome != variant_index {
                    return None; // Tested, but found the wrong variant.
                }

                // Correct variant. Extract the subitems and match
                // those. The lvalue goes gets downcast, so
                // e.g. `foo.bar` becomes `foo.bar as Variant`.
                let elem = ProjectionElem::Downcast(adt_def, variant_index);
                let downcast_lvalue = match_pair.lvalue.clone().elem(elem);
                let consequent_match_pairs =
                    subpatterns.into_iter()
                               .map(|subpattern| {
                                   let lvalue =
                                       downcast_lvalue.clone().field(
                                           subpattern.field);
                                   self.match_pair(lvalue, subpattern.pattern)
                               })
                               .collect();
                Some(consequent_match_pairs)
            }

            PatternKind::Constant { value: Literal::Value { ref value } }
            if is_switch_ty(match_pair.pattern.ty) => {
                match *test_kind {
                    TestKind::SwitchInt { switch_ty: _, options: _, ref indices } => {
                        let index = indices[value];
                        if index == test_outcome {
                            Some(vec![]) // this value, nothing left to test
                        } else {
                            None // some other value, candidate is inapplicable
                        }
                    }

                    _ => {
                        self.hir.span_bug(
                            match_pair.pattern.span,
                            &format!("did a switch-int, but value {:?} not found in cases",
                                     value));
                    }
                }
            }

            PatternKind::Constant { .. } |
            PatternKind::Range { .. } |
            PatternKind::Slice { .. } => {
                if test_outcome == 0 {
                    Some(vec![])
                } else {
                    None
                }
            }

            PatternKind::Array { .. } |
            PatternKind::Wild |
            PatternKind::Binding { .. } |
            PatternKind::Leaf { .. } |
            PatternKind::Deref { .. } => {
                self.error_simplifyable(&match_pair)
            }
        }
    }
/// Given that we executed `test` with outcome `test_outcome`,
/// what are the resulting match pairs? This can return either:
///
/// - None, meaning that the test indicated that this outcome
///   means that this match-pair is not the current one for the
///   current discriminant (which rules out the enclosing
///   candidate);
/// - Some(...), meaning that either the test didn't tell us whether this
///   match-pair is correct or not, or that we DID match and now have
///   subsequent matches to perform.
///
/// As an example, consider:
///
/// ```
/// match option {
///     Ok(<pattern>) => ...,
///     Err(_) => ...,
/// }
/// ```
///
/// Suppose that the `test` is a `Switch` and the outcome is
/// `Ok`. Then in that case, the first arm will have a match-pair
/// of `option @ Ok(<pattern>)`. In that case we will return
/// `Some(vec![(option as Ok) @ <pattern>])`. The `Some` reuslt
/// indicates that the match-pair still applies, and we now have
/// to test `(option as Ok) @ <pattern>`.
///
/// On the second arm, a `None` will be returned, because if we
/// observed that `option` has the discriminant `Ok`, then the
/// second arm cannot apply.
Given that we executed `test` with outcome `test_outcome`,
what are the resulting match pairs. This can return either.

None, meaning that the test indicated that this outcome
means that this match-pair is not the current one for the
current discriminant (which rules out the enclosing
candidate);
Some(...), meaning that either the test didn't tell us whether this
match-pair is correct or not, or that we DID match and now have
subsequent matches to perform.

As an example, consider.






Given that we executed ` test ` with outcome ` test_outcome ` what are the resulting match pairs . This can return either . None meaning that the test indicated that this outcome means that this match - pair is not the current one for the current discriminant ( which rules out the enclosing candidate ) ; Some ( ... ) meaning that either the test didn ' t tell us whether this match - pair is correct or not or that we DID match and now have subsequent matches to perform . As an example consider .
pub fn consequent_match_pairs_under_assumption(&mut self,
                                                   match_pair: MatchPair<'tcx>,
                                                   test_kind: &TestKind<'tcx>,
                                                   test_outcome: usize)
                                                   -> Option<Vec<MatchPair<'tcx>>> {
        match match_pair.pattern.kind {
            PatternKind::Variant { adt_def, variant_index, subpatterns } => {
                assert!(match *test_kind { TestKind::Switch { .. } => true,
                                           _ => false });
                if test_outcome != variant_index {
                    return None; // Tested, but found the wrong variant.
                }
                // Correct variant. Extract the subitems and match
                // those. The lvalue goes gets downcast, so
                // e.g. `foo.bar` becomes `foo.bar as Variant`.
                let elem = ProjectionElem::Downcast(adt_def, variant_index);
                let downcast_lvalue = match_pair.lvalue.clone().elem(elem);
                let consequent_match_pairs =
                    subpatterns.into_iter()
                               .map(|subpattern| {
                                   let lvalue =
                                       downcast_lvalue.clone().field(
                                           subpattern.field);
                                   self.match_pair(lvalue, subpattern.pattern)
                               })
                               .collect();
                Some(consequent_match_pairs)
            }
            PatternKind::Constant { value: Literal::Value { ref value } }
            if is_switch_ty(match_pair.pattern.ty) => {
                match *test_kind {
                    TestKind::SwitchInt { switch_ty: _, options: _, ref indices } => {
                        let index = indices[value];
                        if index == test_outcome {
                            Some(vec![]) // this value, nothing left to test
                        } else {
                            None // some other value, candidate is inapplicable
                        }
                    }
                    _ => {
                        self.hir.span_bug(
                            match_pair.pattern.span,
                            &format!("did a switch-int, but value {:?} not found in cases",
                                     value));
                    }
                }
            }
            PatternKind::Constant { .. } |
            PatternKind::Range { .. } |
            PatternKind::Slice { .. } => {
                if test_outcome == 0 {
                    Some(vec![])
                } else {
                    None
                }
            }
            PatternKind::Array { .. } |
            PatternKind::Wild |
            PatternKind::Binding { .. } |
            PatternKind::Leaf { .. } |
            PatternKind::Deref { .. } => {
                self.error_simplifyable(&match_pair)
            }
        }
    }
pub fn consequent_match_pairs_under_assumption ( & mut self , match_pair : MatchPair < ' tcx > , test_kind : & TestKind < ' tcx > , test_outcome : usize ) -> Option < Vec < MatchPair < ' tcx > > > { match match_pair . pattern . kind { PatternKind :: Variant { adt_def , variant_index , subpatterns } => { assert ! ( match test_kind { TestKind Switch { } true false } ) ; if test_outcome != variant_index { return None ; // Tested, but found the wrong variant. } // Correct variant. Extract the subitems and match // those. The lvalue goes gets downcast, so // e.g. `foo.bar` becomes `foo.bar as Variant`. let elem = ProjectionElem :: Downcast ( adt_def , variant_index ) ; let downcast_lvalue = match_pair . lvalue . clone ( ) . elem ( elem ) ; let consequent_match_pairs = subpatterns . into_iter ( ) . map ( | subpattern | { let lvalue = downcast_lvalue . clone ( ) . field ( subpattern . field ) ; self . match_pair ( lvalue , subpattern . pattern ) } ) . collect ( ) ; Some ( consequent_match_pairs ) } PatternKind :: Constant { value : Literal :: Value { ref value } } if is_switch_ty ( match_pair . pattern . ty ) => { match * test_kind { TestKind :: SwitchInt { switch_ty : _ , options : _ , ref indices } => { let index = indices [ value ] ; if index == test_outcome { Some ( vec ! [ ] ) // this value, nothing left to test } else { None // some other value, candidate is inapplicable } } _ => { self . hir . span_bug ( match_pair . pattern . span , & format ! ( " " value ) ) ; } } } PatternKind :: Constant { .. } | PatternKind :: Range { .. } | PatternKind :: Slice { .. } => { if test_outcome == 0 { Some ( vec ! [ ] ) } else { None } } PatternKind :: Array { .. } | PatternKind :: Wild | PatternKind :: Binding { .. } | PatternKind :: Leaf { .. } | PatternKind :: Deref { .. } => { self . error_simplifyable ( & match_pair ) } } }
Given that we executed `test` with outcome `test_outcome`,
what are the resulting match pairs?
Given that we executed ` test ` with outcome ` test_outcome ` what are the resulting match pairs?
&mut self
match_pair
MatchPair<'tcx>
test_kind
&TestKind<'tcx>
test_outcome
usize