rustc_utils/mir/
operand.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Utilities for [`Operand`].

use rustc_middle::mir::{Operand, Place};

/// Extension trait for [`Operand`].
pub trait OperandExt<'tcx> {
  /// Extracts the [`Place`] inside an [`Operand`] if it exists.
  fn as_place(&self) -> Option<Place<'tcx>>;
}

impl<'tcx> OperandExt<'tcx> for Operand<'tcx> {
  fn as_place(&self) -> Option<Place<'tcx>> {
    match self {
      Operand::Copy(place) | Operand::Move(place) => Some(*place),
      Operand::Constant(_) => None,
    }
  }
}