rustc_pattern_analysis::rustc

Struct 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>

source

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.

source

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.

source

pub fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool

source

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].

source

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).

source

pub(crate) fn variant_sub_tys( &self, ty: RevealedTy<'tcx>, variant: &'tcx VariantDef, ) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> + Captures<'p> + Captures<'_>

source

pub(crate) fn variant_index_for_adt( ctor: &Constructor<'p, 'tcx>, adt: AdtDef<'tcx>, ) -> VariantIdx

source

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().

source

pub(crate) fn ctor_arity( &self, ctor: &Constructor<'p, 'tcx>, ty: RevealedTy<'tcx>, ) -> usize

The number of fields for this constructor.

source

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.

source

pub(crate) fn lower_pat_range_bdy( &self, bdy: PatRangeBoundary<'tcx>, ty: RevealedTy<'tcx>, ) -> MaybeInfiniteInt

source

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.

source

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.

source

fn print_pat_range(&self, range: &IntRange, ty: RevealedTy<'tcx>) -> String

Prints an IntRange to a string for diagnostic purposes.

source

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>

source§

fn clone(&self) -> RustcPatCtxt<'p, 'tcx>

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'p, 'tcx: 'p> Debug for RustcPatCtxt<'p, 'tcx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx>

source§

type Ty = RevealedTy<'tcx>

The type of a pattern.
source§

type Error = ErrorGuaranteed

Errors that can abort analysis.
source§

type VariantIdx = VariantIdx

The index of an enum variant.
source§

type StrLit = Const<'tcx>

A string literal
source§

type ArmData = HirId

Extra data to store in a match arm.
source§

type PatData = &'p Pat<'tcx>

Extra data to store in a pattern.
source§

fn is_exhaustive_patterns_feature_on(&self) -> bool

source§

fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize

The number of fields for this constructor.
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>

The types of the fields for this constructor. The result must contain ctor_arity() fields.
source§

fn ctors_for_ty( &self, ty: &Self::Ty, ) -> Result<ConstructorSet<Self>, Self::Error>

The set of all the constructors for ty. Read more
source§

fn write_variant_name( f: &mut Formatter<'_>, ctor: &Constructor<Self>, ty: &Self::Ty, ) -> Result

Write the name of the variant represented by pat. Used for the best-effort Debug impl of DeconstructedPat. Only invoqued when pat.ctor() is Struct | Variant(_) | UnionField.
source§

fn bug(&self, fmt: Arguments<'_>) -> Self::Error

Raise a bug.
source§

fn lint_overlapping_range_endpoints( &self, pat: &DeconstructedPat<Self>, overlaps_on: IntRange, overlaps_with: &[&DeconstructedPat<Self>], )

Lint that the range 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>

The maximum pattern complexity limit was reached.
source§

fn lint_non_contiguous_range_endpoints( &self, pat: &DeconstructedPat<Self>, gap: IntRange, gapped_with: &[&DeconstructedPat<Self>], )

Lint that there is a gap 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> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

source§

type Output = R

source§

impl<T> Filterable for T

source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<P> IntoQueryParam<P> for P

source§

impl<T> MaybeResult<T> for T

source§

type Error = !

source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

source§

fn upcast(self, interner: I) -> U

source§

impl<I, T> UpcastFrom<I, T> for T

source§

fn upcast_from(from: T, _tcx: I) -> T

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

source§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<T> ErasedDestructor for T
where 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: 72 bytes