pub mod constructor;
#[cfg(feature = "rustc")]
pub mod errors;
#[cfg(feature = "rustc")]
pub(crate) mod lints;
pub mod pat;
#[cfg(feature = "rustc")]
pub mod rustc;
pub mod usefulness;
#[macro_use]
extern crate tracing;
#[cfg(feature = "rustc")]
#[macro_use]
extern crate rustc_middle;
#[cfg(feature = "rustc")]
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
use std::fmt;
use rustc_index::Idx;
#[cfg(feature = "rustc")]
use rustc_middle::ty::Ty;
use crate::constructor::{Constructor, ConstructorSet};
#[cfg(feature = "rustc")]
use crate::lints::{
lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints, PatternColumn,
};
use crate::pat::DeconstructedPat;
#[cfg(feature = "rustc")]
use crate::rustc::RustcMatchCheckCtxt;
#[cfg(feature = "rustc")]
use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
#[cfg(feature = "rustc")]
pub(crate) use rustc_arena::TypedArena;
#[cfg(feature = "stable")]
pub(crate) use typed_arena::Arena as TypedArena;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
pub trait TypeCx: Sized + Clone + fmt::Debug {
type Ty: Copy + Clone + fmt::Debug; type VariantIdx: Clone + Idx;
type StrLit: Clone + PartialEq + fmt::Debug;
type ArmData: Copy + Clone + fmt::Debug;
type PatData: Clone + Default;
fn is_opaque_ty(ty: Self::Ty) -> bool;
fn is_exhaustive_patterns_feature_on(&self) -> bool;
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: Self::Ty) -> usize;
fn ctor_sub_tys(&self, ctor: &Constructor<Self>, ty: Self::Ty) -> &[Self::Ty];
fn ctors_for_ty(&self, ty: Self::Ty) -> ConstructorSet<Self>;
fn debug_pat(f: &mut fmt::Formatter<'_>, pat: &DeconstructedPat<'_, Self>) -> fmt::Result;
fn bug(&self, fmt: fmt::Arguments<'_>) -> !;
}
#[derive(Clone)]
pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
pub tycx: &'a Cx,
pub wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
}
impl<'a, 'p, Cx: TypeCx> Copy for MatchCtxt<'a, 'p, Cx> {}
#[derive(Clone, Debug)]
pub struct MatchArm<'p, Cx: TypeCx> {
pub pat: &'p DeconstructedPat<'p, Cx>,
pub has_guard: bool,
pub arm_data: Cx::ArmData,
}
impl<'p, Cx: TypeCx> Copy for MatchArm<'p, Cx> {}
#[cfg(feature = "rustc")]
pub fn analyze_match<'p, 'tcx>(
tycx: &RustcMatchCheckCtxt<'p, 'tcx>,
arms: &[rustc::MatchArm<'p, 'tcx>],
scrut_ty: Ty<'tcx>,
) -> rustc::UsefulnessReport<'p, 'tcx> {
let wildcard_arena = tycx.pattern_arena;
let scrut_validity = ValidityConstraint::from_bool(tycx.known_valid_scrutinee);
let cx = MatchCtxt { tycx, wildcard_arena };
let report = compute_match_usefulness(cx, arms, scrut_ty, scrut_validity);
let pat_column = PatternColumn::new(arms);
lint_overlapping_range_endpoints(cx, &pat_column);
if tycx.refutable && report.non_exhaustiveness_witnesses.is_empty() {
lint_nonexhaustive_missing_variants(cx, arms, &pat_column, scrut_ty)
}
report
}