Rvalue in rustc_public::mir::body - Rust
Description: API documentation for the Rust `Rvalue` enum in crate `rustc_public`.

Skip to main content

## Rvalue

# Enum Rvalue

Source

    pub enum Rvalue {
    Show 14 variants    AddressOf(RawPtrKind, 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, TyConst),
        ThreadLocalRef(CrateItem),
        UnaryOp(UnOp, Operand),
        Use(Operand, WithRetag),
        Reborrow(Ty, Mutability, Place),
    }

## Variants§

§

### AddressOf(RawPtrKind, 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 `Coroutine`. After coroutine lowering, `Coroutine` 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 a `usize` as well.
- The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats, raw pointers, or function pointers and return a `bool`. 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, TyConst)

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]`.

§

### 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?

§

### 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, WithRetag)

Yields the operand unchanged, except for possibly a retag.

§

### Reborrow(Ty, Mutability, Place)

Creates a bitwise copy of the source type, producing either a value of the same type (when Mutability::Mut) or a different type with a guaranteed equal memory layout defined by the CoerceShared trait. See `Rvalue::Reborrow` for a more detailed explanation.

## Implementations§

Source§

### impl Rvalue

Source

#### pub fn ty(&self, locals: &[LocalDecl]) -> Result<Ty, Error>

## Trait Implementations§

Source§

### impl Clone for Rvalue

Source§

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

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 Debug for Rvalue

Source§

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

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

### impl Eq for Rvalue

Source§

### impl Hash for Rvalue

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 Rvalue

Source§

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

Tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 (const: unstable) · 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 Rvalue

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 StructuralPartialEq for Rvalue

## Auto Trait Implementations§

§

### impl !DynSend for Rvalue

§

### impl !DynSync for Rvalue

§

### impl !Send for Rvalue

§

### impl !Sync for Rvalue

§

### impl Freeze for Rvalue

§

### impl RefUnwindSafe for Rvalue

§

### impl Unpin for Rvalue

§

### impl UnsafeUnpin for Rvalue

§

### impl UnwindSafe for Rvalue

## 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<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> ErasedDestructor for T
where T: 'static,

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

## 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: 248 bytes

Size for each variant:

- `AddressOf`: 39 bytes
- `Aggregate`: 103 bytes
- `BinaryOp`: 247 bytes
- `Cast`: 135 bytes
- `CheckedBinaryOp`: 247 bytes
- `CopyForDeref`: 39 bytes
- `Discriminant`: 39 bytes
- `Len`: 39 bytes
- `Ref`: 95 bytes
- `Repeat`: 207 bytes
- `ThreadLocalRef`: 15 bytes
- `UnaryOp`: 127 bytes
- `Use`: 127 bytes
- `Reborrow`: 47 bytes