Skip to main content

ItemRef

Struct ItemRef 

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

Source

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.

Source

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>

Source

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.

Source

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.

Source

pub fn translate_projection<S: UnderOwnerState<'tcx>>( s: &S, def_id: RDefId, generics: GenericArgs<'tcx>, ) -> ItemRef<'tcx>

Source

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>

Source

pub fn identity<S: UnderOwnerState<'tcx>>(s: &S, def_id: DefId) -> ItemRef<'tcx>

The item with its identity arguments.

Source

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

Source

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.

Source

pub fn erase<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Self

Erase free lifetimes and anonymise bound ones from the generic arguments of this item.

Source

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.

Source

pub fn contents(&self) -> &ItemRefContents<'tcx>

Source

pub fn peel_derived<S: BaseState<'tcx>>(&self, s: &S) -> Self

Return a reference to the underlying item, if this item is derived.

Source

pub fn derived_base<S: BaseState<'tcx>>(&self, s: &S) -> Self

Return a reference to the (recursive) base item.

Source

pub fn rustc_args<S: BaseState<'tcx>>(&self, _s: &S) -> GenericArgs<'tcx>

Recover the original rustc args that generated this ItemRef.

Source

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.

Source

pub fn with_def_id<S: BaseState<'tcx>>(&self, s: &S, def_id: &DefId) -> Self

Set the DefId, keeping the same generic args.

Source

pub fn make_derived<S: UnderOwnerState<'tcx>>( &self, s: &S, kind: DerivedItemKind, ) -> Self

Refer to the derived item, with the same generics.

Source

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.

Source

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.

Source

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

Source

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

  1. the suffix of the arguments that was cut off, if any, and
  2. 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>

Source

pub fn translate_synthetic<S: UnderOwnerState<'tcx>>( s: &S, synthetic: SyntheticItem, generics: GenericArgs<'tcx>, ) -> ItemRef<'tcx>

Source

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§

Source§

impl<'tcx> Clone for ItemRef<'tcx>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tcx> Debug for ItemRef<'tcx>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'tcx> Deref for ItemRef<'tcx>

Source§

type Target = ItemRefContents<'tcx>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'tcx> Eq for ItemRef<'tcx>

Source§

impl<'tcx> Hash for ItemRef<'tcx>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'tcx> PartialEq for ItemRef<'tcx>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl RefUnwindSafe for ItemRef<'_>

Source§

impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for GlobalRef

The global standing for self.

Source§

fn sinto(&self, s: &S) -> ItemRef<'tcx>

Source§

impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for ItemRef<'tcx, DefId>

Source§

fn sinto(&self, s: &S) -> ItemRef<'tcx>

Source§

impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ItemRef<'tcx>> for TraitRef<'tcx>

Source§

fn sinto(&self, s: &S) -> TraitRef<'tcx>

Source§

impl<'tcx> StructuralPartialEq for ItemRef<'tcx>

Source§

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> 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Dedup for T
where T: Mappable + Clone + Eq + Hash,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HashConsable for T
where T: Hash + PartialEq + Eq + Clone + Mappable,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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<T> Mappable for T
where T: Any + Send + Sync,

Source§

impl<T> MergeValue for T
where T: PartialEq + Debug,

Source§

fn merge(&mut self, other: T)

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more