crate fn compute_match_usefulness<'p, 'tcx>(
    cx: &MatchCheckCtxt<'p, 'tcx>,
    arms: &[MatchArm<'p, 'tcx>],
    scrut_hir_id: HirId,
    scrut_ty: Ty<'tcx>,
) -> UsefulnessReport<'p, 'tcx> {
    let mut matrix = Matrix::empty();
    let arm_usefulness: Vec<_> = arms
        .iter()
        .copied()
        .map(|arm| {
            let v = PatStack::from_pattern(arm.pat);
            let usefulness =
                is_useful(cx, &matrix, &v, LeaveOutWitness, arm.hir_id, arm.has_guard, true);
            if !arm.has_guard {
                matrix.push(v);
            }
            (arm, usefulness)
        })
        .collect();

    let wild_pattern = cx.pattern_arena.alloc(super::Pat::wildcard_from_ty(scrut_ty));
    let v = PatStack::from_pattern(wild_pattern);
    let usefulness = is_useful(cx, &matrix, &v, ConstructWitness, scrut_hir_id, false, true);
    let non_exhaustiveness_witnesses = match usefulness {
        NotUseful => vec![], // Wildcard pattern isn't useful, so the match is exhaustive.
        UsefulWithWitness(pats) => {
            if pats.is_empty() {
                bug!("Exhaustiveness check returned no witnesses")
            } else {
                pats.into_iter().map(|w| w.single_pattern()).collect()
            }
        }
        Useful(_) => bug!(),
    };
    UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses }
}
/// The entrypoint for the usefulness algorithm. Computes whether a match is exhaustive and which
/// of its arms are reachable.
///
/// Note: the input patterns must have been lowered through `MatchVisitor::lower_pattern`.
The entrypoint for the usefulness algorithm. Computes whether a match is exhaustive and which
of its arms are reachable.

the input patterns must have been lowered through `MatchVisitor::lower_pattern`.
The entrypoint for the usefulness algorithm . Computes whether a match is exhaustive and which of its arms are reachable . the input patterns must have been lowered through ` MatchVisitor :: lower_pattern ` .
crate fn compute_match_usefulness<'p, 'tcx>(
    cx: &MatchCheckCtxt<'p, 'tcx>,
    arms: &[MatchArm<'p, 'tcx>],
    scrut_hir_id: HirId,
    scrut_ty: Ty<'tcx>,
) -> UsefulnessReport<'p, 'tcx> {
    let mut matrix = Matrix::empty();
    let arm_usefulness: Vec<_> = arms
        .iter()
        .copied()
        .map(|arm| {
            let v = PatStack::from_pattern(arm.pat);
            let usefulness =
                is_useful(cx, &matrix, &v, LeaveOutWitness, arm.hir_id, arm.has_guard, true);
            if !arm.has_guard {
                matrix.push(v);
            }
            (arm, usefulness)
        })
        .collect();
    let wild_pattern = cx.pattern_arena.alloc(super::Pat::wildcard_from_ty(scrut_ty));
    let v = PatStack::from_pattern(wild_pattern);
    let usefulness = is_useful(cx, &matrix, &v, ConstructWitness, scrut_hir_id, false, true);
    let non_exhaustiveness_witnesses = match usefulness {
        NotUseful => vec![], // Wildcard pattern isn't useful, so the match is exhaustive.
        UsefulWithWitness(pats) => {
            if pats.is_empty() {
                bug!("Exhaustiveness check returned no witnesses")
            } else {
                pats.into_iter().map(|w| w.single_pattern()).collect()
            }
        }
        Useful(_) => bug!(),
    };
    UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses }
}
crate fn compute_match_usefulness < ' p , ' tcx > ( cx : & MatchCheckCtxt < ' p , ' tcx > , arms : & [ MatchArm < ' p , ' tcx > ] , scrut_hir_id : HirId , scrut_ty : Ty < ' tcx > , ) -> UsefulnessReport < ' p , ' tcx > { let mut matrix = Matrix :: empty ( ) ; let arm_usefulness : Vec < _ > = arms . iter ( ) . copied ( ) . map ( | arm | { let v = PatStack :: from_pattern ( arm . pat ) ; let usefulness = is_useful ( cx , & matrix , & v , LeaveOutWitness , arm . hir_id , arm . has_guard , true ) ; if ! arm . has_guard { matrix . push ( v ) ; } ( arm , usefulness ) } ) . collect ( ) ; let wild_pattern = cx . pattern_arena . alloc ( super :: Pat :: wildcard_from_ty ( scrut_ty ) ) ; let v = PatStack :: from_pattern ( wild_pattern ) ; let usefulness = is_useful ( cx , & matrix , & v , ConstructWitness , scrut_hir_id , false , true ) ; let non_exhaustiveness_witnesses = match usefulness { NotUseful => vec ! [ ] , // Wildcard pattern isn't useful, so the match is exhaustive. UsefulWithWitness ( pats ) => { if pats . is_empty ( ) { bug ! ( " " ) } else { pats . into_iter ( ) . map ( | w | w . single_pattern ( ) ) . collect ( ) } } Useful ( _ ) => bug ! ( ) , } ; UsefulnessReport { arm_usefulness , non_exhaustiveness_witnesses } }
The entrypoint for the usefulness algorithm.
The entrypoint for the usefulness algorithm .
cx
&MatchCheckCtxt<'p, 'tcx>
arms
&[MatchArm<'p, 'tcx>]
scrut_hir_id
HirId
scrut_ty
Ty<'tcx>
cx
&MatchCheckCtxt<'p, 'tcx>
arms
&[MatchArm<'p, 'tcx>]
scrut_hir_id
HirId
scrut_ty
Ty<'tcx>