1
Fork 0

interpret: use Either over Result when it is not representing an error condition

This commit is contained in:
Ralf Jung 2022-11-18 10:18:32 +01:00
parent 83356b78c4
commit 4101889786
17 changed files with 130 additions and 98 deletions

View file

@ -7,6 +7,8 @@
//! but we still need to do bounds checking and adjust the layout. To not duplicate that with MPlaceTy, we actually
//! implement the logic on OpTy, and MPlaceTy calls that.
use either::{Left, Right};
use rustc_middle::mir;
use rustc_middle::ty;
use rustc_middle::ty::layout::LayoutOf;
@ -84,13 +86,13 @@ where
base: &OpTy<'tcx, M::Provenance>,
field: usize,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
let base = match base.try_as_mplace() {
Ok(ref mplace) => {
let base = match base.as_mplace_or_imm() {
Left(ref mplace) => {
// We can reuse the mplace field computation logic for indirect operands.
let field = self.mplace_field(mplace, field)?;
return Ok(field.into());
}
Err(value) => value,
Right(value) => value,
};
let field_layout = base.layout.field(self, field);