pub struct RustcPatCtxt<'p, 'tcx: 'p> {
pub tcx: TyCtxt<'tcx>,
pub typeck_results: &'tcx TypeckResults<'tcx>,
pub module: DefId,
pub typing_env: TypingEnv<'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.
typing_env: TypingEnv<'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> !DynSend for RustcPatCtxt<'p, 'tcx>
impl<'p, 'tcx> !DynSync for RustcPatCtxt<'p, 'tcx>
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§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<T> Pointable for T
impl<T> Pointable 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,
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: 88 bytes