pub struct ItemRef {
pub(crate) contents: Node<ItemRefContents>,
}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],
impl_exprs = [<proof of `String: Sized`>],
in_trait = Some(<proof of `SelfType: MyTrait<TraitType, 12>`>,
}The in_trait ImplExpr 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],
impl_exprs = [],
in_trait = None,
}Fields§
§contents: Node<ItemRefContents>Implementations§
Source§impl ItemRef
impl ItemRef
Sourcepub fn instantiated_full_def<'tcx, S, Body>(&self, s: &S) -> Arc<FullDef<Body>>
pub fn instantiated_full_def<'tcx, S, Body>(&self, s: &S) -> Arc<FullDef<Body>>
Get the full definition of the item, instantiated with the provided generics.
Source§impl ItemRef
impl ItemRef
Sourcepub fn translate<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
def_id: RDefId,
generics: GenericArgsRef<'tcx>,
) -> ItemRef
pub fn translate<'tcx, S: UnderOwnerState<'tcx>>( s: &S, def_id: RDefId, generics: GenericArgsRef<'tcx>, ) -> ItemRef
The main way to obtain an ItemRef: from a def_id and generics.
Sourcefn translate_maybe_resolve_impl<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
resolve_impl: bool,
def_id: RDefId,
generics: GenericArgsRef<'tcx>,
) -> ItemRef
fn translate_maybe_resolve_impl<'tcx, S: UnderOwnerState<'tcx>>( s: &S, resolve_impl: bool, def_id: RDefId, generics: GenericArgsRef<'tcx>, ) -> ItemRef
Makes a ItemRef from a def_id and generics.
If resolve_impl == true and (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.
Sourcepub fn dummy_without_generics<'tcx, S: BaseState<'tcx>>(
s: &S,
def_id: DefId,
) -> ItemRef
pub fn dummy_without_generics<'tcx, S: BaseState<'tcx>>( s: &S, def_id: DefId, ) -> ItemRef
Construct an ItemRef for items that can’t have generics (e.g. modules).
Sourcepub fn trait_associated_types<'tcx, S: UnderOwnerState<'tcx>>(
&self,
s: &S,
) -> Vec<Ty>
pub fn trait_associated_types<'tcx, S: UnderOwnerState<'tcx>>( &self, s: &S, ) -> Vec<Ty>
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<'tcx, S: UnderOwnerState<'tcx>>(&self, s: &S) -> Self
pub fn erase<'tcx, S: UnderOwnerState<'tcx>>(&self, s: &S) -> Self
Erase lifetimes from the generic arguments of this item.
pub fn contents(&self) -> &ItemRefContents
Sourcepub fn rustc_args<'tcx, S: BaseState<'tcx>>(
&self,
s: &S,
) -> GenericArgsRef<'tcx>
pub fn rustc_args<'tcx, S: BaseState<'tcx>>( &self, s: &S, ) -> GenericArgsRef<'tcx>
Recover the original rustc args that generated this ItemRef. Will panic if the ItemRef
was built by hand instead of using translate_item_ref.
Sourcepub fn mutate_def_id<'tcx, S: BaseState<'tcx>>(
&self,
s: &S,
f: impl FnOnce(&mut DefId),
) -> Self
pub fn mutate_def_id<'tcx, 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<'tcx, S: BaseState<'tcx>>(
&self,
s: &S,
def_id: &DefId,
) -> Self
pub fn with_def_id<'tcx, S: BaseState<'tcx>>( &self, s: &S, def_id: &DefId, ) -> Self
Set the DefId, keeping the same generic args.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ItemRef
impl<'de> Deserialize<'de> for ItemRef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for ItemRef
impl JsonSchema for ItemRef
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreSource§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§impl Ord for ItemRef
impl Ord for ItemRef
Source§impl PartialOrd for ItemRef
impl PartialOrd for ItemRef
Source§impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef> for TraitRef<'tcx>
Available on crate feature rustc only.
impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef> for TraitRef<'tcx>
rustc only.impl Eq for ItemRef
impl StructuralPartialEq for ItemRef
Auto Trait Implementations§
impl Freeze for ItemRef
impl RefUnwindSafe for ItemRef
impl Send for ItemRef
impl Sync for ItemRef
impl Unpin for ItemRef
impl UnwindSafe for ItemRef
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,
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 more