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
impl Instance
Sourcepub fn args(&self) -> GenericArgs
pub fn args(&self) -> GenericArgs
Get the arguments this instance was instantiated with.
Sourcepub fn body(&self) -> Option<Body>
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.
Sourcepub fn has_body(&self) -> bool
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 StableMIR body.
pub fn is_foreign_item(&self) -> bool
Sourcepub fn ty(&self) -> Ty
pub fn ty(&self) -> Ty
Get the instance type with generic instantiations applied and lifetimes erased.
Sourcepub fn fn_abi(&self) -> Result<FnAbi, Error>
pub fn fn_abi(&self) -> Result<FnAbi, Error>
Retrieve information about this instance binary interface.
Sourcepub fn mangled_name(&self) -> String
pub fn mangled_name(&self) -> String
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.
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Retrieve the instance name for diagnostic messages.
This will return the specialized name, e.g., std::vec::Vec<u8>::new
.
Sourcepub fn trimmed_name(&self) -> String
pub fn trimmed_name(&self) -> String
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.
Sourcepub fn intrinsic_name(&self) -> Option<String>
pub fn intrinsic_name(&self) -> Option<String>
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.
Sourcepub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error>
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error>
Resolve an instance starting from a function definition and generic arguments.
Sourcepub fn resolve_drop_in_place(ty: Ty) -> Instance
pub fn resolve_drop_in_place(ty: Ty) -> Instance
Resolve the drop in place for a given type.
Sourcepub fn resolve_for_fn_ptr(
def: FnDef,
args: &GenericArgs,
) -> Result<Instance, Error>
pub fn resolve_for_fn_ptr( def: FnDef, args: &GenericArgs, ) -> Result<Instance, Error>
Resolve an instance for a given function pointer.
Sourcepub fn resolve_closure(
def: ClosureDef,
args: &GenericArgs,
kind: ClosureKind,
) -> Result<Instance, Error>
pub fn resolve_closure( def: ClosureDef, args: &GenericArgs, kind: ClosureKind, ) -> Result<Instance, Error>
Resolve a closure with the expected kind.
Sourcepub fn is_empty_shim(&self) -> bool
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 StableMIR 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.
Sourcepub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error>
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
.
Trait Implementations§
Source§impl RustcInternal for Instance
impl RustcInternal for Instance
Source§impl Serialize for Instance
impl Serialize for Instance
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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.
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§impl TryFrom<Instance> for CrateItem
Try to convert an instance into a crate item.
Only user defined instances can be converted.
impl TryFrom<Instance> for CrateItem
Try to convert an instance into a crate item. Only user defined instances can be converted.
impl Copy for Instance
impl Eq for Instance
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 UnwindSafe for Instance
Blanket Implementations§
Source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
Source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
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, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
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