rustc_pattern_analysis/
lib.rs1#![allow(rustc::diagnostic_outside_of_impl)]
7#![allow(rustc::untranslatable_diagnostic)]
8#![allow(unused_crate_dependencies)]
9pub mod constructor;
12#[cfg(feature = "rustc")]
13pub mod errors;
14#[cfg(feature = "rustc")]
15pub(crate) mod lints;
16pub mod pat;
17pub mod pat_column;
18#[cfg(feature = "rustc")]
19pub mod rustc;
20pub mod usefulness;
21
22#[cfg(feature = "rustc")]
23rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
24
25use std::fmt;
26
27pub use rustc_index::{Idx, IndexVec}; use crate::constructor::{Constructor, ConstructorSet, IntRange};
30use crate::pat::DeconstructedPat;
31
32pub trait Captures<'a> {}
33impl<'a, T: ?Sized> Captures<'a> for T {}
34
35#[derive(Copy, Clone, Debug, PartialEq, Eq)]
38pub struct PrivateUninhabitedField(pub bool);
39
40pub trait PatCx: Sized + fmt::Debug {
44 type Ty: Clone + fmt::Debug;
46 type Error: fmt::Debug;
48 type VariantIdx: Clone + Idx + fmt::Debug;
50 type StrLit: Clone + PartialEq + fmt::Debug;
52 type ArmData: Copy + Clone + fmt::Debug;
54 type PatData: Clone;
56
57 fn is_exhaustive_patterns_feature_on(&self) -> bool;
58
59 fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;
61
62 fn ctor_sub_tys(
64 &self,
65 ctor: &Constructor<Self>,
66 ty: &Self::Ty,
67 ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator;
68
69 fn ctors_for_ty(&self, ty: &Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
73
74 fn write_variant_name(
77 f: &mut fmt::Formatter<'_>,
78 ctor: &crate::constructor::Constructor<Self>,
79 ty: &Self::Ty,
80 ) -> fmt::Result;
81
82 fn bug(&self, fmt: fmt::Arguments<'_>) -> Self::Error;
84
85 fn lint_overlapping_range_endpoints(
89 &self,
90 _pat: &DeconstructedPat<Self>,
91 _overlaps_on: IntRange,
92 _overlaps_with: &[&DeconstructedPat<Self>],
93 ) {
94 }
95
96 fn complexity_exceeded(&self) -> Result<(), Self::Error>;
98
99 fn lint_non_contiguous_range_endpoints(
104 &self,
105 _pat: &DeconstructedPat<Self>,
106 _gap: IntRange,
107 _gapped_with: &[&DeconstructedPat<Self>],
108 ) {
109 }
110}
111
112#[derive(Debug)]
114pub struct MatchArm<'p, Cx: PatCx> {
115 pub pat: &'p DeconstructedPat<Cx>,
116 pub has_guard: bool,
117 pub arm_data: Cx::ArmData,
118}
119
120impl<'p, Cx: PatCx> Clone for MatchArm<'p, Cx> {
121 fn clone(&self) -> Self {
122 Self { pat: self.pat, has_guard: self.has_guard, arm_data: self.arm_data }
123 }
124}
125
126impl<'p, Cx: PatCx> Copy for MatchArm<'p, Cx> {}