rustc_utils/mir/
operand.rs

1//! Utilities for [`Operand`].
2
3use rustc_middle::mir::{Operand, Place};
4
5/// Extension trait for [`Operand`].
6pub trait OperandExt<'tcx> {
7  /// Extracts the [`Place`] inside an [`Operand`] if it exists.
8  fn as_place(&self) -> Option<Place<'tcx>>;
9}
10
11impl<'tcx> OperandExt<'tcx> for Operand<'tcx> {
12  fn as_place(&self) -> Option<Place<'tcx>> {
13    match self {
14      Operand::Copy(place) | Operand::Move(place) => Some(*place),
15      Operand::Constant(_) => None,
16    }
17  }
18}