diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index fc8eccb2705..a67bc53d2b4 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -270,9 +270,10 @@ fn handle_rvalue( val } Rvalue::UnaryOp(op, operand) => match self.eval_operand(operand, state) { - FlatSet::Elem(value) => { - self.ecx.unary_op(*op, &value).map_or(FlatSet::Top, |val| self.wrap_immty(val)) - } + FlatSet::Elem(value) => self + .ecx + .unary_op(*op, &value) + .map_or(FlatSet::Top, |val| self.wrap_immediate(*val)), FlatSet::Bottom => FlatSet::Bottom, FlatSet::Top => FlatSet::Top, }, @@ -420,9 +421,9 @@ fn assign_constant( &mut |place, op| { if let Ok(imm) = self.ecx.read_immediate_raw(op) && let Some(imm) = imm.right() - && let Immediate::Scalar(scalar) = *imm { - state.insert_value_idx(place, FlatSet::Elem(scalar), &self.map); + let elem = self.wrap_immediate(*imm); + state.insert_value_idx(place, elem, &self.map); } }, ); @@ -492,10 +493,9 @@ fn eval_operand( FlatSet::Top => FlatSet::Top, FlatSet::Elem(scalar) => { let ty = op.ty(self.local_decls, self.tcx); - self.tcx - .layout_of(self.param_env.and(ty)) - .map(|layout| FlatSet::Elem(ImmTy::from_scalar(scalar.into(), layout))) - .unwrap_or(FlatSet::Top) + self.tcx.layout_of(self.param_env.and(ty)).map_or(FlatSet::Top, |layout| { + FlatSet::Elem(ImmTy::from_scalar(scalar.into(), layout)) + }) } FlatSet::Bottom => FlatSet::Bottom, } @@ -514,13 +514,10 @@ fn eval_discriminant(&self, enum_ty: Ty<'tcx>, variant_index: VariantIdx) -> Opt fn wrap_immediate(&self, imm: Immediate) -> FlatSet { match imm { Immediate::Scalar(scalar) => FlatSet::Elem(scalar), + Immediate::Uninit => FlatSet::Bottom, _ => FlatSet::Top, } } - - fn wrap_immty(&self, val: ImmTy<'tcx>) -> FlatSet { - self.wrap_immediate(*val) - } } struct CollectAndPatch<'tcx, 'locals> {