Struct rustc_pattern_analysis::rustc::RustcPatCtxt
source · pub struct RustcPatCtxt<'p, 'tcx: 'p> {
pub tcx: TyCtxt<'tcx>,
pub typeck_results: &'tcx TypeckResults<'tcx>,
pub module: DefId,
pub param_env: ParamEnv<'tcx>,
pub dropless_arena: &'p DroplessArena,
pub match_lint_level: HirId,
pub whole_match_span: Option<Span>,
pub scrut_span: Span,
pub refutable: bool,
pub known_valid_scrutinee: bool,
}
Fields§
§tcx: TyCtxt<'tcx>
§typeck_results: &'tcx TypeckResults<'tcx>
§module: DefId
The module in which the match occurs. This is necessary for
checking inhabited-ness of types because whether a type is (visibly)
inhabited can depend on whether it was defined in the current module or
not. E.g., struct Foo { _private: ! }
cannot be seen to be empty
outside its module and should not be matchable with an empty match statement.
param_env: ParamEnv<'tcx>
§dropless_arena: &'p DroplessArena
To allocate the result of self.ctor_sub_tys()
match_lint_level: HirId
Lint level at the match.
whole_match_span: Option<Span>
The span of the whole match, if applicable.
scrut_span: Span
Span of the scrutinee.
refutable: bool
Only produce NON_EXHAUSTIVE_OMITTED_PATTERNS
lint on refutable patterns.
known_valid_scrutinee: bool
Whether the data at the scrutinee is known to be valid. This is false if the scrutinee comes from a union field, a pointer deref, or a reference deref (pending opsem decisions).
Implementations§
source§impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx>
sourcepub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx>
pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx>
Type inference occasionally gives us opaque types in places where corresponding patterns have more specific types. To avoid inconsistencies as well as detect opaque uninhabited types, we use the corresponding concrete type if possible.
sourcefn reveal_opaque_key(&self, key: OpaqueTypeKey<'tcx>) -> Option<Ty<'tcx>>
fn reveal_opaque_key(&self, key: OpaqueTypeKey<'tcx>) -> Option<Ty<'tcx>>
Returns the hidden type corresponding to this key if the body under analysis is allowed to know it.
pub fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool
sourcepub fn is_foreign_non_exhaustive_enum(&self, ty: RevealedTy<'tcx>) -> bool
pub fn is_foreign_non_exhaustive_enum(&self, ty: RevealedTy<'tcx>) -> bool
Returns whether the given type is an enum from another crate declared #[non_exhaustive]
.
sourcepub fn is_range_beyond_boundaries(
&self,
range: &IntRange,
ty: RevealedTy<'tcx>,
) -> bool
pub fn is_range_beyond_boundaries( &self, range: &IntRange, ty: RevealedTy<'tcx>, ) -> bool
Whether the range denotes the fictitious values before isize::MIN
or after
usize::MAX
/isize::MAX
(see doc of IntRange::split
for why these exist).
pub(crate) fn variant_sub_tys( &self, ty: RevealedTy<'tcx>, variant: &'tcx VariantDef, ) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> + Captures<'p> + Captures<'_>
pub(crate) fn variant_index_for_adt( ctor: &Constructor<'p, 'tcx>, adt: AdtDef<'tcx>, ) -> VariantIdx
sourcepub(crate) fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a Constructor<'p, 'tcx>,
ty: RevealedTy<'tcx>,
) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
pub(crate) fn ctor_sub_tys<'a>( &'a self, ctor: &'a Constructor<'p, 'tcx>, ty: RevealedTy<'tcx>, ) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
Returns the types of the fields for a given constructor. The result must have a length of
ctor.arity()
.
sourcepub(crate) fn ctor_arity(
&self,
ctor: &Constructor<'p, 'tcx>,
ty: RevealedTy<'tcx>,
) -> usize
pub(crate) fn ctor_arity( &self, ctor: &Constructor<'p, 'tcx>, ty: RevealedTy<'tcx>, ) -> usize
The number of fields for this constructor.
sourcepub fn ctors_for_ty(
&self,
ty: RevealedTy<'tcx>,
) -> Result<ConstructorSet<'p, 'tcx>, ErrorGuaranteed>
pub fn ctors_for_ty( &self, ty: RevealedTy<'tcx>, ) -> Result<ConstructorSet<'p, 'tcx>, ErrorGuaranteed>
Creates a set that represents all the constructors of ty
.
See crate::constructor
for considerations of emptiness.
pub(crate) fn lower_pat_range_bdy( &self, bdy: PatRangeBoundary<'tcx>, ty: RevealedTy<'tcx>, ) -> MaybeInfiniteInt
sourcepub fn lower_pat(&self, pat: &'p Pat<'tcx>) -> DeconstructedPat<'p, 'tcx>
pub fn lower_pat(&self, pat: &'p Pat<'tcx>) -> DeconstructedPat<'p, 'tcx>
Note: the input patterns must have been lowered through
rustc_mir_build::thir::pattern::check_match::MatchVisitor::lower_pattern
.
sourcefn hoist_pat_range_bdy(
&self,
miint: MaybeInfiniteInt,
ty: RevealedTy<'tcx>,
) -> PatRangeBoundary<'tcx>
fn hoist_pat_range_bdy( &self, miint: MaybeInfiniteInt, ty: RevealedTy<'tcx>, ) -> PatRangeBoundary<'tcx>
Convert back to a thir::PatRangeBoundary
for diagnostic purposes.
Note: it is possible to get isize/usize::MAX+1
here, as explained in the doc for
IntRange::split
. This cannot be represented as a Const
, so we represent it with
PosInfinity
.
sourcefn print_pat_range(&self, range: &IntRange, ty: RevealedTy<'tcx>) -> String
fn print_pat_range(&self, range: &IntRange, ty: RevealedTy<'tcx>) -> String
Prints an IntRange
to a string for diagnostic purposes.
sourcepub fn print_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> String
pub fn print_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> String
Prints a WitnessPat
to an owned string, for diagnostic purposes.
This panics for patterns that don’t appear in diagnostics, like float ranges.
Trait Implementations§
source§impl<'p, 'tcx: 'p> Clone for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx: 'p> Clone for RustcPatCtxt<'p, 'tcx>
source§fn clone(&self) -> RustcPatCtxt<'p, 'tcx>
fn clone(&self) -> RustcPatCtxt<'p, 'tcx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'p, 'tcx: 'p> Debug for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx: 'p> Debug for RustcPatCtxt<'p, 'tcx>
source§impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx>
source§type Ty = RevealedTy<'tcx>
type Ty = RevealedTy<'tcx>
source§type Error = ErrorGuaranteed
type Error = ErrorGuaranteed
source§type VariantIdx = VariantIdx
type VariantIdx = VariantIdx
fn is_exhaustive_patterns_feature_on(&self) -> bool
source§fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize
source§fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a Constructor<Self>,
ty: &'a Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
fn ctor_sub_tys<'a>( &'a self, ctor: &'a Constructor<Self>, ty: &'a Self::Ty, ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
ctor_arity()
fields.source§fn ctors_for_ty(
&self,
ty: &Self::Ty,
) -> Result<ConstructorSet<Self>, Self::Error>
fn ctors_for_ty( &self, ty: &Self::Ty, ) -> Result<ConstructorSet<Self>, Self::Error>
ty
. Read moresource§fn write_variant_name(
f: &mut Formatter<'_>,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> Result
fn write_variant_name( f: &mut Formatter<'_>, ctor: &Constructor<Self>, ty: &Self::Ty, ) -> Result
pat
. Used for the best-effort Debug
impl of
DeconstructedPat
. Only invoqued when pat.ctor()
is Struct | Variant(_) | UnionField
.source§fn lint_overlapping_range_endpoints(
&self,
pat: &DeconstructedPat<Self>,
overlaps_on: IntRange,
overlaps_with: &[&DeconstructedPat<Self>],
)
fn lint_overlapping_range_endpoints( &self, pat: &DeconstructedPat<Self>, overlaps_on: IntRange, overlaps_with: &[&DeconstructedPat<Self>], )
pat
overlapped with all the ranges in overlaps_with
, where the range
they overlapped over is overlaps_on
. We only detect singleton overlaps.
The default implementation does nothing.source§fn complexity_exceeded(&self) -> Result<(), Self::Error>
fn complexity_exceeded(&self) -> Result<(), Self::Error>
source§fn lint_non_contiguous_range_endpoints(
&self,
pat: &DeconstructedPat<Self>,
gap: IntRange,
gapped_with: &[&DeconstructedPat<Self>],
)
fn lint_non_contiguous_range_endpoints( &self, pat: &DeconstructedPat<Self>, gap: IntRange, gapped_with: &[&DeconstructedPat<Self>], )
gap
between pat
and all of gapped_with
such that the gap is
not matched by another range. If gapped_with
is empty, then gap
is T::MAX
. We only
detect singleton gaps.
The default implementation does nothing.Auto Trait Implementations§
impl<'p, 'tcx> Freeze for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx> !RefUnwindSafe for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx> !Send for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx> !Sync for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx> Unpin for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx> !UnwindSafe for RustcPatCtxt<'p, 'tcx>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 72 bytes