Instance in rustc_public::mir::mono - Rust
Description: API documentation for the Rust `Instance` struct in crate `rustc_public`.

Skip to main content

## Instance

# Struct Instance

Source

    pub struct Instance {
        pub kind: InstanceKind,
        pub def: InstanceDef,
    }

## Fields§

§`kind: InstanceKind`

The type of instance.

§`def: InstanceDef`

An ID used to get the instance definition from the compiler. Do not use this field directly.

## Implementations§

Source§

### impl Instance

Source

#### pub fn args(&self) -> GenericArgs

Get the arguments this instance was instantiated with.

Source

#### pub fn body(&self) -> Option<Body>

Get the body of an Instance.

The body will be eagerly monomorphized and all constants will already be evaluated.

This method will return the intrinsic fallback body if one was defined.

Source

#### pub fn has_body(&self) -> bool

Check whether this instance has a body available.

For intrinsics with fallback body, this will return `true`. It is up to the user to decide whether to specialize the intrinsic or to use its fallback body.

For more information on fallback body, see https://github.com/rust-lang/rust/issues/93145.

This call is much cheaper than `instance.body().is_some()`, since it doesn’t try to build the rustc_public’s IR body.

Source

#### pub fn is_foreign_item(&self) -> bool

Source

#### pub fn ty(&self) -> Ty

Get the instance type with generic instantiations applied and lifetimes erased.

Source

#### pub fn fn_abi(&self) -> Result<FnAbi, Error>

Retrieve information about this instance binary interface.

Source

#### pub fn mangled_name(&self) -> Symbol

Retrieve the instance’s mangled name used for calling the given instance.

This will also look up the correct name of instances from upstream crates.

Source

#### pub fn name(&self) -> Symbol

Retrieve the instance name for diagnostic messages.

This will return the specialized name, e.g., `std::vec::Vec<u8>::new`.

Source

#### pub fn trimmed_name(&self) -> Symbol

Return a trimmed name of the given instance including its args.

If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we trim its path and print only the name.

Source

#### pub fn intrinsic_name(&self) -> Option<Symbol>

Retrieve the plain intrinsic name of an instance if it’s an intrinsic.

The plain name does not include type arguments (as `trimmed_name` does), which is more convenient to match with intrinsic symbols.

Source

#### pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error>

Resolve an instance starting from a function definition and generic arguments.

Source

#### pub fn resolve_drop_in_place(ty: Ty) -> Instance

Resolve the drop in place for a given type.

Source

#### pub fn resolve_for_fn_ptr( def: FnDef, args: &GenericArgs, ) -> Result<Instance, Error>

Resolve an instance for a given function pointer.

Source

#### pub fn resolve_closure( def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Result<Instance, Error>

Resolve a closure with the expected kind.

Source

#### pub fn is_empty_shim(&self) -> bool

Check whether this instance is an empty shim.

Allow users to check if this shim can be ignored when called directly.

We have decided not to export different types of Shims to rustc_public users, however, this is a query that can be very helpful for users when processing DropGlue.

When generating code for a Drop terminator, users can ignore an empty drop glue. These shims are only needed to generate a valid Drop call done via VTable.

Source

#### pub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error>

Try to constant evaluate the instance into a constant with the given type.

This can be used to retrieve a constant that represents an intrinsic return such as `type_id`.

Source

#### pub fn emit_mir<W: Write>(&self, w: &mut W) -> Result<()>

Emit the body of this instance if it has one.

## Trait Implementations§

Source§

### impl Clone for Instance

Source§

#### fn clone(&self) -> Instance

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from `source`. Read more
Source§

### impl Debug for Instance

Source§

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

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

### impl From<Instance> for MonoItem

Source§

#### fn from(value: Instance) -> Self

Converts to this type from the input type.
Source§

### impl From<StaticDef> for Instance

Source§

#### fn from(value: StaticDef) -> Self

Converts to this type from the input type.
Source§

### impl Hash for Instance

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 PartialEq for Instance

Source§

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

Tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 · Source§

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

Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

### impl Serialize for Instance

Source§

#### fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

### impl TryFrom<CrateItem> for Instance

Try to convert a crate item into an instance. The item cannot be generic in order to be converted into an instance.

Source§

#### type Error = Error

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

#### fn try_from(item: CrateItem) -> Result<Self, Self::Error>

Performs the conversion.
Source§

### impl TryFrom<Instance> for CrateItem

Try to convert an instance into a crate item. Only user defined instances can be converted.

Source§

#### type Error = Error

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

#### fn try_from(value: Instance) -> Result<Self, Self::Error>

Performs the conversion.
Source§

### impl TryFrom<Instance> for StaticDef

Source§

#### type Error = Error

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

#### fn try_from(value: Instance) -> Result<Self, Self::Error>

Performs the conversion.
Source§

### impl Copy for Instance

Source§

### impl Eq for Instance

Source§

### impl StructuralPartialEq for Instance

## Auto Trait Implementations§

§

### impl !DynSend for Instance

§

### impl !DynSync for Instance

§

### impl Freeze for Instance

§

### impl RefUnwindSafe for Instance

§

### impl !Send for Instance

§

### impl !Sync for Instance

§

### impl Unpin for Instance

§

### impl UnsafeUnpin for Instance

§

### impl UnwindSafe for Instance

## Blanket Implementations§

Source§

### impl<T> Aligned for T

Source§

#### const ALIGN: Alignment

Alignment of `Self`.
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> AnyEq for T
where T: Any + PartialEq,

Source§

#### fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

#### fn as_any(&self) -> &(dyn Any + 'static)

Source§

### impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T
where T: Copy,

Source§

#### fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T

Source§

#### fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]

Source§

### impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T
where T: Copy,

Source§

#### fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T

Source§

#### fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]

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, R> CollectAndApply<T, R> for T

Source§

#### fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to `f(&iter.collect::<Vec<_>>())`.

Source§

#### type Output = R

Source§

### impl<T> DynClone for T
where T: Clone,

Source§

#### fn __clone_box(&self, _: Private) -> *mut ()

Source§

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

Source§

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

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

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

Source§

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

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

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

Source§

#### 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> Instrument for T

Source§

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

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

#### 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<K> IntoQueryKey<K> for K

Source§

#### fn into_query_key(self) -> K

Argument conversion from `Self` to `K`. This should always be a very cheap conversion, e.g. `LocalDefId::to_def_id`.
Source§

### impl<T> MaybeResult<T> for T

Source§

#### type Error = !

Source§

#### fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

Source§

#### fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

Source§

### impl<T> Pointable for T

Source§

#### const ALIGN: usize

The alignment of pointer.
Source§

#### type Init = T

The type for initializers.
Source§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

### impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

Source§

#### fn upcast(self, interner: I) -> U

Source§

### impl<I, T> UpcastFrom<I, T> for T

Source§

#### fn upcast_from(from: T, _tcx: I) -> T

Source§

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

Source§

#### fn vzip(self) -> V

Source§

### impl<T> WithSubscriber for T

Source§

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

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

Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more
Source§

### impl<T> ErasedDestructor for T
where 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: 24 bytes