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

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
1.0.0 · 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 u8)

🔬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: 88 bytes