Skip to content

Commit 09a887c

Browse files
committed
review feedback
1 parent 4101889 commit 09a887c

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
364364
pub fn read_immediate_raw(
365365
&self,
366366
src: &OpTy<'tcx, M::Provenance>,
367-
) -> InterpResult<'tcx, Either<ImmTy<'tcx, M::Provenance>, MPlaceTy<'tcx, M::Provenance>>> {
367+
) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, ImmTy<'tcx, M::Provenance>>> {
368368
Ok(match src.as_mplace_or_imm() {
369369
Left(ref mplace) => {
370370
if let Some(val) = self.read_immediate_from_mplace_raw(mplace)? {
371-
Left(val)
371+
Right(val)
372372
} else {
373-
Right(*mplace)
373+
Left(*mplace)
374374
}
375375
}
376-
Right(val) => Left(val),
376+
Right(val) => Right(val),
377377
})
378378
}
379379

@@ -392,7 +392,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
392392
) {
393393
span_bug!(self.cur_span(), "primitive read not possible for type: {:?}", op.layout.ty);
394394
}
395-
let imm = self.read_immediate_raw(op)?.left().unwrap();
395+
let imm = self.read_immediate_raw(op)?.right().unwrap();
396396
if matches!(*imm, Immediate::Uninit) {
397397
throw_ub!(InvalidUninitBytes(None));
398398
}

compiler/rustc_const_eval/src/interpret/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ where
641641
// Let us see if the layout is simple so we take a shortcut,
642642
// avoid force_allocation.
643643
let src = match self.read_immediate_raw(src)? {
644-
Left(src_val) => {
644+
Right(src_val) => {
645645
// FIXME(const_prop): Const-prop can possibly evaluate an
646646
// unsized copy operation when it thinks that the type is
647647
// actually sized, due to a trivially false where-clause
@@ -671,7 +671,7 @@ where
671671
)
672672
};
673673
}
674-
Right(mplace) => mplace,
674+
Left(mplace) => mplace,
675675
};
676676
// Slow path, this does not fit into an immediate. Just memcpy.
677677
trace!("copy_op: {:?} <- {:?}: {}", *dest, src, dest.layout.ty);

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ impl IntRange {
147147
// straight to the result, after doing a bit of checking. (We
148148
// could remove this branch and just fall through, which
149149
// is more general but much slower.)
150-
if let either::Left(bits) =
151-
scalar.to_bits_or_ptr_internal(target_size).unwrap()
152-
{
153-
return Some(bits);
154-
} else {
155-
return None;
156-
}
150+
return scalar.to_bits_or_ptr_internal(target_size).unwrap().left();
157151
}
158152
mir::ConstantKind::Ty(c) => match c.kind() {
159153
ty::ConstKind::Value(_) => bug!(

compiler/rustc_mir_transform/src/const_prop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use std::cell::Cell;
55

6-
use either::Left;
6+
use either::Right;
77

88
use rustc_ast::Mutability;
99
use rustc_data_structures::fx::FxHashSet;
@@ -431,7 +431,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
431431
// Try to read the local as an immediate so that if it is representable as a scalar, we can
432432
// handle it as such, but otherwise, just return the value as is.
433433
Some(match self.ecx.read_immediate_raw(&op) {
434-
Ok(Left(imm)) => imm.into(),
434+
Ok(Right(imm)) => imm.into(),
435435
_ => op,
436436
})
437437
}
@@ -745,7 +745,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
745745
// FIXME> figure out what to do when read_immediate_raw fails
746746
let imm = self.use_ecx(|this| this.ecx.read_immediate_raw(value));
747747

748-
if let Some(Left(imm)) = imm {
748+
if let Some(Right(imm)) = imm {
749749
match *imm {
750750
interpret::Immediate::Scalar(scalar) => {
751751
*rval = Rvalue::Use(self.operand_from_scalar(

0 commit comments

Comments
 (0)