ra_ap_rustc_pattern_analysis/
lib.rs1#![allow(rustc::diagnostic_outside_of_impl)]
7#![allow(rustc::untranslatable_diagnostic)]
8#![cfg_attr(feature = "rustc", feature(let_chains))]
9#![warn(unreachable_pub)]
10pub mod constructor;
13#[cfg(feature = "rustc")]
14pub mod errors;
15#[cfg(feature = "rustc")]
16pub(crate) mod lints;
17pub mod pat;
18pub mod pat_column;
19#[cfg(feature = "rustc")]
20pub mod rustc;
21pub mod usefulness;
22
23#[cfg(feature = "rustc")]
24rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
25
26use std::fmt;
27
28pub use rustc_index::{Idx, IndexVec}; use crate::constructor::{Constructor, ConstructorSet, IntRange};
31use crate::pat::DeconstructedPat;
32
33pub trait Captures<'a> {}
34impl<'a, T: ?Sized> Captures<'a> for T {}
35
36#[derive(Copy, Clone, Debug, PartialEq, Eq)]
39pub struct PrivateUninhabitedField(pub bool);
40
41pub trait PatCx: Sized + fmt::Debug {
45    type Ty: Clone + fmt::Debug;
47    type Error: fmt::Debug;
49    type VariantIdx: Clone + Idx + fmt::Debug;
51    type StrLit: Clone + PartialEq + fmt::Debug;
53    type ArmData: Copy + Clone + fmt::Debug;
55    type PatData: Clone;
57
58    fn is_exhaustive_patterns_feature_on(&self) -> bool;
59
60    fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;
62
63    fn ctor_sub_tys(
65        &self,
66        ctor: &Constructor<Self>,
67        ty: &Self::Ty,
68    ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator;
69
70    fn ctors_for_ty(&self, ty: &Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
74
75    fn write_variant_name(
78        f: &mut fmt::Formatter<'_>,
79        ctor: &crate::constructor::Constructor<Self>,
80        ty: &Self::Ty,
81    ) -> fmt::Result;
82
83    fn bug(&self, fmt: fmt::Arguments<'_>) -> Self::Error;
85
86    fn lint_overlapping_range_endpoints(
90        &self,
91        _pat: &DeconstructedPat<Self>,
92        _overlaps_on: IntRange,
93        _overlaps_with: &[&DeconstructedPat<Self>],
94    ) {
95    }
96
97    fn complexity_exceeded(&self) -> Result<(), Self::Error>;
99
100    fn lint_non_contiguous_range_endpoints(
105        &self,
106        _pat: &DeconstructedPat<Self>,
107        _gap: IntRange,
108        _gapped_with: &[&DeconstructedPat<Self>],
109    ) {
110    }
111}
112
113#[derive(Debug)]
115pub struct MatchArm<'p, Cx: PatCx> {
116    pub pat: &'p DeconstructedPat<Cx>,
117    pub has_guard: bool,
118    pub arm_data: Cx::ArmData,
119}
120
121impl<'p, Cx: PatCx> Clone for MatchArm<'p, Cx> {
122    fn clone(&self) -> Self {
123        Self { pat: self.pat, has_guard: self.has_guard, arm_data: self.arm_data }
124    }
125}
126
127impl<'p, Cx: PatCx> Copy for MatchArm<'p, Cx> {}