Enum stable_mir::mir::body::Rvalue
source · pub enum Rvalue {
Show 15 variants
AddressOf(Mutability, Place),
Aggregate(AggregateKind, Vec<Operand>),
BinaryOp(BinOp, Operand, Operand),
Cast(CastKind, Operand, Ty),
CheckedBinaryOp(BinOp, Operand, Operand),
CopyForDeref(Place),
Discriminant(Place),
Len(Place),
Ref(Region, BorrowKind, Place),
Repeat(Operand, Const),
ShallowInitBox(Operand, Ty),
ThreadLocalRef(CrateItem),
NullaryOp(NullOp, Ty),
UnaryOp(UnOp, Operand),
Use(Operand),
}
Variants§
AddressOf(Mutability, Place)
Creates a pointer with the indicated mutability to the place.
This is generated by pointer casts like &v as *const _
or raw address of expressions like
&raw v
or addr_of!(v)
.
Aggregate(AggregateKind, Vec<Operand>)
Creates an aggregate value, like a tuple or struct.
This is needed because dataflow analysis needs to distinguish
dest = Foo { x: ..., y: ... }
from dest.x = ...; dest.y = ...;
in the case that Foo
has a destructor.
Disallowed after deaggregation for all aggregate kinds except Array
and Generator
. After
generator lowering, Generator
aggregate kinds are disallowed too.
BinaryOp(BinOp, Operand, Operand)
Offset
has the same semantics as<*const T>::offset
, except that the second parameter may be ausize
as well.- The comparison operations accept
bool
s,char
s, signed or unsigned integers, floats, raw pointers, or function pointers and return abool
. The types of the operands must be matching, up to the usual caveat of the lifetimes in function pointers. - Left and right shift operations accept signed or unsigned integers not necessarily of the same type and return a value of the same type as their LHS. Like in Rust, the RHS is truncated as needed.
- The
Bit*
operations accept signed integers, unsigned integers, or bools with matching types and return a value of that type. - The remaining operations accept signed integers, unsigned integers, or floats with matching types and return a value of that type.
Cast(CastKind, Operand, Ty)
Performs essentially all of the casts that can be performed via as
.
This allows for casts from/to a variety of types.
CheckedBinaryOp(BinOp, Operand, Operand)
Same as BinaryOp
, but yields (T, bool)
with a bool
indicating an error condition.
For addition, subtraction, and multiplication on integers the error condition is set when the infinite precision result would not be equal to the actual result.
CopyForDeref(Place)
A CopyForDeref is equivalent to a read from a place. When such a read happens, it is guaranteed that the only use of the returned value is a deref operation, immediately followed by one or more projections.
Discriminant(Place)
Computes the discriminant of the place, returning it as an integer. Returns zero for types without discriminant.
The validity requirements for the underlying value are undecided for this rvalue, see #91095. Note too that the value of the discriminant is not the same thing as the variant index;
Len(Place)
Yields the length of the place, as a usize
.
If the type of the place is an array, this is the array length. For slices ([T]
, not
&[T]
) this accesses the place’s metadata to determine the length. This rvalue is
ill-formed for places of other types.
Ref(Region, BorrowKind, Place)
Creates a reference to the place.
Repeat(Operand, Const)
Creates an array where each element is the value of the operand.
This is the cause of a bug in the case where the repetition count is zero because the value is not dropped, see #74836.
Corresponds to source code like [x; 32]
.
ShallowInitBox(Operand, Ty)
Transmutes a *mut u8
into shallow-initialized Box<T>
.
This is different from a normal transmute because dataflow analysis will treat the box as initialized but its content as uninitialized. Like other pointer casts, this in general affects alias analysis.
ThreadLocalRef(CrateItem)
Creates a pointer/reference to the given thread local.
The yielded type is a *mut T
if the static is mutable, otherwise if the static is extern a
*const T
, and if neither of those apply a &T
.
Note: This is a runtime operation that actually executes code and is in this sense more
like a function call. Also, eliminating dead stores of this rvalue causes fn main() {}
to
SIGILL for some reason that I (JakobDegen) never got a chance to look into.
Needs clarification: Are there weird additional semantics here related to the runtime nature of this operation?
NullaryOp(NullOp, Ty)
Computes a value as described by the operation.
UnaryOp(UnOp, Operand)
Exactly like BinaryOp
, but less operands.
Also does two’s-complement arithmetic. Negation requires a signed integer or a float; bitwise not requires a signed integer, unsigned integer, or bool. Both operation kinds return a value with the same type as their operand.
Use(Operand)
Yields the operand unchanged
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Rvalue
impl Send for Rvalue
impl Sync for Rvalue
impl Unpin for Rvalue
impl UnwindSafe for Rvalue
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
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: 200 bytes
Size for each variant:
AddressOf
: 39 bytesAggregate
: 103 bytesBinaryOp
: 199 bytesCast
: 111 bytesCheckedBinaryOp
: 199 bytesCopyForDeref
: 39 bytesDiscriminant
: 39 bytesLen
: 39 bytesRef
: 103 bytesRepeat
: 175 bytesShallowInitBox
: 111 bytesThreadLocalRef
: 15 bytesNullaryOp
: 47 bytesUnaryOp
: 103 bytesUse
: 103 bytes