pub struct ItemRef<'tcx> {
pub(crate) contents: Interned<'tcx, ItemRefContents<'tcx>>,
}Expand description
Reference to an item, with generics. Basically any mention of an item (function, type, etc) uses this.
This can refer to a top-level item or to a trait associated item. Example:
trait MyTrait<TraitType, const TraitConst: usize> {
fn meth<MethType>(...) {...}
}
fn example_call<TraitType, SelfType: MyTrait<TraitType, 12>>(x: SelfType) {
x.meth::<String>(...)
}Here, in the call x.meth::<String>(...) we will build an ItemRef that looks like:
ItemRef {
def_id = MyTrait::meth,
generic_args = [String],
trait_proofs = [<proof of `String: Sized`>],
in_trait = Some(<proof of `SelfType: MyTrait<TraitType, 12>`>,
}The in_trait TraitProof will have in its trait field a representation of the SelfType: MyTrait<TraitType, 12> predicate, which looks like:
ItemRef {
def_id = MyTrait,
generic_args = [SelfType, TraitType, 12],
trait_proofs = [],
in_trait = None,
}Fields§
§contents: Interned<'tcx, ItemRefContents<'tcx>>Implementations§
Source§impl<'tcx> ItemRef<'tcx>
impl<'tcx> ItemRef<'tcx>
Sourcepub fn instantiated_full_def<S>(&self, s: &S) -> Arc<FullDef<'tcx>> ⓘwhere
S: BaseState<'tcx>,
pub fn instantiated_full_def<S>(&self, s: &S) -> Arc<FullDef<'tcx>> ⓘwhere
S: BaseState<'tcx>,
Get the full definition of the item, instantiated with the provided generics.
Sourcepub fn drop_glue_shim<S>(&self, s: &S) -> Body<'tcx>where
S: BaseState<'tcx>,
pub fn drop_glue_shim<S>(&self, s: &S) -> Body<'tcx>where
S: BaseState<'tcx>,
Get the drop glue shim for this. Panics if the DefKind isn’t appropriate.
Source§impl<'tcx> ItemRef<'tcx>
impl<'tcx> ItemRef<'tcx>
Sourcepub fn translate<S: UnderOwnerState<'tcx>>(
s: &S,
def_id: RDefId,
generics: GenericArgs<'tcx>,
) -> ItemRef<'tcx>
pub fn translate<S: UnderOwnerState<'tcx>>( s: &S, def_id: RDefId, generics: GenericArgs<'tcx>, ) -> ItemRef<'tcx>
The main way to obtain an ItemRef: from a def_id and generics.
Sourcepub fn translate_from_frontend_def_id<S: UnderOwnerState<'tcx>>(
s: &S,
frontend_def_id: DefId,
generics: GenericArgs<'tcx>,
) -> ItemRef<'tcx>
pub fn translate_from_frontend_def_id<S: UnderOwnerState<'tcx>>( s: &S, frontend_def_id: DefId, generics: GenericArgs<'tcx>, ) -> ItemRef<'tcx>
Makes a ItemRef from a def_id and generics.
If (def_id, generics) points to a trait item that can be resolved to a specific impl,
translate rewrites def_id to the concrete associated item from that impl and re-bases
the generics.
For instance, <u32 as From<u8>>::from produces a ItemRef with a DefId looking
like core::convert::num::Impl#42::from when resolve_impl is true,
core::convert::From::from otherwise.
pub fn translate_projection<S: UnderOwnerState<'tcx>>( s: &S, def_id: RDefId, generics: GenericArgs<'tcx>, ) -> ItemRef<'tcx>
pub fn translate_from_frontend_def_id_maybe_resolve<S: UnderOwnerState<'tcx>>( s: &S, frontend_def_id: DefId, generics: GenericArgs<'tcx>, assoc_item_resolution: AssocItemResolution, ) -> ItemRef<'tcx>
Sourcepub fn identity<S: UnderOwnerState<'tcx>>(s: &S, def_id: DefId) -> ItemRef<'tcx>
pub fn identity<S: UnderOwnerState<'tcx>>(s: &S, def_id: DefId) -> ItemRef<'tcx>
The item with its identity arguments.
Sourcepub fn dummy_without_generics<S: BaseState<'tcx>>(
s: &S,
def_id: DefId,
) -> ItemRef<'tcx>
pub fn dummy_without_generics<S: BaseState<'tcx>>( s: &S, def_id: DefId, ) -> ItemRef<'tcx>
Construct an ItemRef for items that can’t have generics (e.g. modules).
Sourcepub fn trait_associated_types<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
) -> Vec<Ty<'tcx>>
pub fn trait_associated_types<S: UnderOwnerState<'tcx>>( &self, s: &S, ) -> Vec<Ty<'tcx>>
For an ItemRef that refers to a trait, this returns values for each of the non-gat
associated types of this trait and its parents, in a fixed order.
Sourcepub fn erase<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Self
pub fn erase<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Self
Erase free lifetimes and anonymise bound ones from the generic arguments of this item.
Sourcepub fn re_resolve<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
assoc_item_resolution: AssocItemResolution,
) -> Self
pub fn re_resolve<S: UnderOwnerState<'tcx>>( &self, s: &S, assoc_item_resolution: AssocItemResolution, ) -> Self
Reconstruct this item reference with the requested associated item resolution.
pub fn contents(&self) -> &ItemRefContents<'tcx>
Sourcepub fn peel_derived<S: BaseState<'tcx>>(&self, s: &S) -> Self
pub fn peel_derived<S: BaseState<'tcx>>(&self, s: &S) -> Self
Return a reference to the underlying item, if this item is derived.
Sourcepub fn derived_base<S: BaseState<'tcx>>(&self, s: &S) -> Self
pub fn derived_base<S: BaseState<'tcx>>(&self, s: &S) -> Self
Return a reference to the (recursive) base item.
Sourcepub fn rustc_args<S: BaseState<'tcx>>(&self, _s: &S) -> GenericArgs<'tcx>
pub fn rustc_args<S: BaseState<'tcx>>(&self, _s: &S) -> GenericArgs<'tcx>
Recover the original rustc args that generated this ItemRef.
Sourcepub fn mutate_def_id<S: BaseState<'tcx>>(
&self,
s: &S,
f: impl FnOnce(&mut DefId),
) -> Self
pub fn mutate_def_id<S: BaseState<'tcx>>( &self, s: &S, f: impl FnOnce(&mut DefId), ) -> Self
Mutate the DefId, keeping the same generic args.
Sourcepub fn with_def_id<S: BaseState<'tcx>>(&self, s: &S, def_id: &DefId) -> Self
pub fn with_def_id<S: BaseState<'tcx>>(&self, s: &S, def_id: &DefId) -> Self
Set the DefId, keeping the same generic args.
Sourcepub fn make_derived<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
kind: DerivedItemKind,
) -> Self
pub fn make_derived<S: UnderOwnerState<'tcx>>( &self, s: &S, kind: DerivedItemKind, ) -> Self
Refer to the derived item, with the same generics.
Sourcepub fn make_derived_keep_resolution<S: BaseState<'tcx>>(
&self,
s: &S,
kind: DerivedItemKind,
) -> Self
pub fn make_derived_keep_resolution<S: BaseState<'tcx>>( &self, s: &S, kind: DerivedItemKind, ) -> Self
Refer to the derived item, with the same generics. Unlike make_derived, this keeps the
in_trait resolution if there was one which can lead to errors. Only used for computing names.
Sourcepub fn make_derived_fn_call_method<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
kind: ClosureKind,
) -> Self
pub fn make_derived_fn_call_method<S: UnderOwnerState<'tcx>>( &self, s: &S, kind: ClosureKind, ) -> Self
Refer to the derived item which is the call_* method of the derived Fn* impl.
Sourcepub fn typing_parent<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
) -> Option<ItemRef<'tcx>>
pub fn typing_parent<S: UnderOwnerState<'tcx>>( &self, s: &S, ) -> Option<ItemRef<'tcx>>
The parent of this item if the item inherits the typing context from its parent (e.g. closures and methods).
Sourcepub fn soft_typing_parent<S: UnderOwnerState<'tcx>>(
&self,
s: &S,
) -> (Option<ItemRef<'tcx>>, GenericArgs<'tcx>, GenericArgs<'tcx>)
pub fn soft_typing_parent<S: UnderOwnerState<'tcx>>( &self, s: &S, ) -> (Option<ItemRef<'tcx>>, GenericArgs<'tcx>, GenericArgs<'tcx>)
Like Self::typing_parent, but includes enclosing closures and inline consts that
rustc does not consider “parents” for the purposes of generic arguments. E.g. a closure has
three extra inference parameters, and a nested closure does not inherit them.
Also returns
- the suffix of the arguments that was cut off, if any, and
- the corresponding suffix of this item’s unerased + instantiated identity args.
These two are almost always the same, except for typeck children: these have some erased
regions in their indentity args, which we will want to unify with the actual provided args
in order to recover their values. The unerased identity args contain placeholder regions at
these erased locations, corresponding to the ParamEnv’s extra_early_regions.
Source§impl<'tcx> ItemRef<'tcx>
impl<'tcx> ItemRef<'tcx>
pub fn translate_synthetic<S: UnderOwnerState<'tcx>>( s: &S, synthetic: SyntheticItem, generics: GenericArgs<'tcx>, ) -> ItemRef<'tcx>
Sourcepub fn translate_fn_ptr<S: UnderOwnerState<'tcx>>(
s: &S,
sig: PolyFnSig<'tcx>,
) -> ItemRef<'tcx>
pub fn translate_fn_ptr<S: UnderOwnerState<'tcx>>( s: &S, sig: PolyFnSig<'tcx>, ) -> ItemRef<'tcx>
Take a fn pointer and construct a reference to the corresponding synthetic item.
Trait Implementations§
impl<'tcx> Eq for ItemRef<'tcx>
impl RefUnwindSafe for ItemRef<'_>
Source§impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for GlobalRef
The global standing for self.
impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for GlobalRef
The global standing for self.
Source§impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for TraitRef<'tcx>
impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for TraitRef<'tcx>
impl<'tcx> StructuralPartialEq for ItemRef<'tcx>
impl UnwindSafe for ItemRef<'_>
Auto Trait Implementations§
impl<'tcx> DynSend for ItemRef<'tcx>
impl<'tcx> DynSync for ItemRef<'tcx>
impl<'tcx> Forget for ItemRef<'tcx>
impl<'tcx> Freeze for ItemRef<'tcx>
impl<'tcx> Move for ItemRef<'tcx>
impl<'tcx> Send for ItemRef<'tcx>
impl<'tcx> Sync for ItemRef<'tcx>
impl<'tcx> Unpin for ItemRef<'tcx>
impl<'tcx> UnsafeUnpin for ItemRef<'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,
impl<T> Dedup for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> HashConsable for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more