Struct rustc_hir_analysis::collect::ItemCtxt
source · pub struct ItemCtxt<'tcx> {
tcx: TyCtxt<'tcx>,
item_def_id: LocalDefId,
tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
}Expand description
Context specific to some particular item. This is what implements HirTyLowerer.
§ItemCtxt vs FnCtxt
ItemCtxt is primarily used to type-check item signatures and lower them
from HIR to their ty::Ty representation, which is exposed using HirTyLowerer.
It’s also used for the bodies of items like structs where the body (the fields)
are just signatures.
This is in contrast to FnCtxt, which is used to type-check bodies of
functions, closures, and consts – anywhere that expressions and statements show up.
An important thing to note is that ItemCtxt does no inference – it has no InferCtxt –
while FnCtxt does do inference.
§Trait predicates
ItemCtxt has information about the predicates that are defined
on the trait. Unfortunately, this predicate information is
available in various different forms at various points in the
process. So we can’t just store a pointer to e.g., the HIR or the
parsed ty form, we have to be more flexible. To this end, the
ItemCtxt is parameterized by a DefId that it uses to satisfy
probe_ty_param_bounds requests, drawing the information from
the HIR (hir::Generics), recursively.
Fields§
§tcx: TyCtxt<'tcx>§item_def_id: LocalDefId§tainted_by_errors: Cell<Option<ErrorGuaranteed>>Implementations§
source§impl<'tcx> ItemCtxt<'tcx>
impl<'tcx> ItemCtxt<'tcx>
sourcefn probe_ty_param_bounds_in_generics(
&self,
hir_generics: &'tcx Generics<'tcx>,
param_def_id: LocalDefId,
ty: Ty<'tcx>,
filter: PredicateFilter,
) -> Vec<(Clause<'tcx>, Span)>
fn probe_ty_param_bounds_in_generics( &self, hir_generics: &'tcx Generics<'tcx>, param_def_id: LocalDefId, ty: Ty<'tcx>, filter: PredicateFilter, ) -> Vec<(Clause<'tcx>, Span)>
Finds bounds from hir::Generics.
This requires scanning through the HIR.
We do this to avoid having to lower all the bounds, which would create artificial cycles.
Instead, we can only lower the bounds for a type parameter X if X::Foo is used.
fn bound_defines_assoc_item( &self, b: &GenericBound<'_>, assoc_name: Ident, ) -> bool
Trait Implementations§
source§impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx>
impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx>
fn tcx(&self) -> TyCtxt<'tcx>
fn dcx(&self) -> DiagCtxtHandle<'_>
source§fn item_def_id(&self) -> LocalDefId
fn item_def_id(&self) -> LocalDefId
LocalDefId of the overarching item whose constituents get lowered.source§fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> Region<'tcx>
fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> Region<'tcx>
source§fn ty_infer(&self, _: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>
fn ty_infer(&self, _: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>
source§fn ct_infer(&self, _: Option<&GenericParamDef>, span: Span) -> Const<'tcx>
fn ct_infer(&self, _: Option<&GenericParamDef>, span: Span) -> Const<'tcx>
source§fn probe_ty_param_bounds(
&self,
span: Span,
def_id: LocalDefId,
assoc_name: Ident,
) -> GenericPredicates<'tcx>
fn probe_ty_param_bounds( &self, span: Span, def_id: LocalDefId, assoc_name: Ident, ) -> GenericPredicates<'tcx>
source§fn lower_assoc_ty(
&self,
span: Span,
item_def_id: DefId,
item_segment: &PathSegment<'tcx>,
poly_trait_ref: PolyTraitRef<'tcx>,
) -> Ty<'tcx>
fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, item_segment: &PathSegment<'tcx>, poly_trait_ref: PolyTraitRef<'tcx>, ) -> Ty<'tcx>
source§fn record_ty(&self, _hir_id: HirId, _ty: Ty<'tcx>, _span: Span)
fn record_ty(&self, _hir_id: HirId, _ty: Ty<'tcx>, _span: Span)
source§fn infcx(&self) -> Option<&InferCtxt<'tcx>>
fn infcx(&self) -> Option<&InferCtxt<'tcx>>
fn lower_fn_sig( &self, decl: &FnDecl<'tcx>, generics: Option<&Generics<'_>>, hir_id: HirId, hir_ty: Option<&Ty<'_>>, ) -> (Vec<Ty<'tcx>>, Ty<'tcx>)
Auto Trait Implementations§
impl<'tcx> DynSend for ItemCtxt<'tcx>
impl<'tcx> !DynSync for ItemCtxt<'tcx>
impl<'tcx> !Freeze for ItemCtxt<'tcx>
impl<'tcx> !RefUnwindSafe for ItemCtxt<'tcx>
impl<'tcx> !Send for ItemCtxt<'tcx>
impl<'tcx> !Sync for ItemCtxt<'tcx>
impl<'tcx> Unpin for ItemCtxt<'tcx>
impl<'tcx> !UnwindSafe for ItemCtxt<'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, 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<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: 16 bytes