Module std::intrinsics
Functions implemented directly in the compiler.
Functions in this module are not intended for general use, and are usually called by wrapper functions in the standard library (e.g. size_of and unreachable).
Intrinsic functions are not first-class citizens. You cannot take a reference to one, or pass it as an argument to another function. The intrinsic call signature is not strictly enforced (pass as many arguments as you want, they will be ignored, the intrinsic may return a value of different type, etc.). Needless to say, intrinsics do not participate in type inference.
Functions
-
Marker return type for intrinsics where the return type is not expressible or depends on the arguments (gasp!) Fail the compilation process with a human-readable message.
Use compile_fail instead.
-
extern "intrinsic" fn compile_warn(reason: &[u8])
Emit a warning message during compilation.
-
extern "intrinsic" fn compile_note(reason: &[u8])
Emit a note during compilation.
-
extern "intrinsic" fn unreachable() -> !
-
extern "intrinsic" fn trap() -> !
Trigger a trap (e.g. through an invalid instruction).
-
extern "intrinsic" fn size_of<T>() -> usize
-
extern "intrinsic" fn type_id<T>() -> usize
-
extern "intrinsic" fn type_name<T>() -> &[u8]
-
extern "intrinsic" fn named_type_name<T>() -> &[u8]
-
extern "intrinsic" fn align_of<T>() -> usize
-
Generate a virtual method table for the given protocol and type.
Do not use directly, use coercion to
&dyn Protocol
instead. Meant to be called from a const initializer. -
extern "intrinsic" fn enum_variants<T>() -> /* computed */
T: EnumEnum variants
Do not use directly, use Type instead. Meant to be called from a const initializer (see ENUM_VARIANTS).
-
Find items by attribute name
It returns a tuple of Types for each item found. Generic arguments can be provided to monomorphize all items with specific type parameters.
There is no stable equivalent in the standard library as the return type is dependent on the input (deep magic lol).
-
Value of a constant or static referenced by a type
Use value instead.
This intrinsic emits a lvalue.
-
extern "intrinsic" fn asm(assembly: &[u8])
Inline assembly
-
extern "intrinsic" fn dangling<Ptr>() -> Ptr
Ptr: Pointer -
extern "intrinsic" fn volatile<Ptr>(ptr: Ptr) -> Ptr
Ptr: Pointer -
extern "intrinsic" fn in_const_context() -> bool
-
extern "intrinsic" fn is_const_evaluable<T>(expr: T) -> bool
-
Panics during constant evaluation (aborts compilation).
Invoking this during normal runtime is undefined behavior.
Use panic instead.
-
extern "intrinsic" fn const_note(msg: &[u8])
Writes a note during constant evaluation.
Invoking this during normal runtime is undefined behavior.
Use println instead.
-
extern "intrinsic" fn const_warning(msg: &[u8])
Writes a warning during constant evaluation.
Invoking this during normal runtime is undefined behavior.
Use eprintln instead.
-
extern "intrinsic" fn const_alloc<T>(size: usize) -> &mut T
-
extern "intrinsic" fn tag<T>(tag: &[u8], val: T) -> T
Identity function.
Adds a tag to the IR subtree. This has no effect on the generated code, but is generally preserved accross passes until codegen. Tags control certain aspects of const evaluation and compiler diagnostics. They are not meant to be used by user code.
Tags are currently added when desugaring certain language constructs, such as
for
loops anddefer
expressions.The type, constness and value-kind of the tagged expression are preserved.
let x = 0; std::intrinsics::tag("foo", x) += 1; // this is valid assert_eq!(x, 1);
Run this exampleNo user-facing equivalent.
-
extern "intrinsic" fn tuple_invoke<Fun, Args, Ret>(f: Fun, args: Args) -> Ret
Fun: Fn(Args, Ret) -
extern "intrinsic" fn stop_iteration() -> !
Stop iteration in a
for const
loop.No user-facing equivalent.
-
extern "intrinsic" fn module_path<T>() -> &[u8]
-
Returns true if the named item has the specified attribute.
-
Lowers the inner expression using the definition span of the provided generic argument.
This intrinsic may return a lvalue.
No stable equivalent.
-
extern "intrinsic" fn codegen_const<T>(name: &[u8]) -> T
Return the value of a C builtin constant
-
extern "intrinsic" fn codegen_func<T>(name: &[u8], ...) -> T
Call a builtin C function
-
extern "intrinsic" fn codegen_type_func<T, Ret>(name: &[u8]) -> T
Call a builtin C "type function" (e.g. sizeof)