Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}

UnaryOp(un_op, ref operand) => {
// The operand always has the same type as the result.
let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?;
let layout = util::unop_homogeneous(un_op).then_some(dest.layout);
let val = self.read_immediate(&self.eval_operand(operand, layout)?)?;
let result = self.unary_op(un_op, &val)?;
assert_eq!(result.layout, dest.layout, "layout mismatch for result of {un_op:?}");
self.write_immediate(*result, &dest)?;
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_const_eval/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ pub fn binop_right_homogeneous(op: mir::BinOp) -> bool {
Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false,
}
}

/// Classify whether an operator is "homogeneous", i.e., the operand has the
/// same type as the result.
#[inline]
pub fn unop_homogeneous(op: mir::UnOp) -> bool {
match op {
mir::UnOp::Not | mir::UnOp::Neg => true,
mir::UnOp::PtrMetadata => false,
}
}
Loading