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 const
s – 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,
filter: PredicateFilter,
) -> Vec<(Clause<'tcx>, Span)>
fn probe_ty_param_bounds_in_generics( &self, hir_generics: &'tcx Generics<'tcx>, param_def_id: LocalDefId, 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.
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>
fn register_trait_ascription_bounds( &self, _: Vec<(Clause<'tcx>, Span)>, _: HirId, span: Span, )
Source§fn probe_ty_param_bounds(
&self,
span: Span,
def_id: LocalDefId,
assoc_name: Ident,
) -> EarlyBinder<'tcx, &'tcx [(Clause<'tcx>, Span)]>
fn probe_ty_param_bounds( &self, span: Span, def_id: LocalDefId, assoc_name: Ident, ) -> EarlyBinder<'tcx, &'tcx [(Clause<'tcx>, Span)]>
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