From ac265cdc19fe99b5909410893dd1583d6cb895fe Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 5 Jul 2022 17:38:46 -0400 Subject: [PATCH] review feedback --- compiler/rustc_codegen_cranelift/src/constant.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/operand.rs | 2 +- compiler/rustc_const_eval/src/const_eval/eval_queries.rs | 2 +- compiler/rustc_const_eval/src/const_eval/valtrees.rs | 2 +- compiler/rustc_const_eval/src/interpret/operand.rs | 2 +- compiler/rustc_middle/src/mir/interpret/value.rs | 6 +++--- compiler/rustc_middle/src/mir/mod.rs | 4 ++-- compiler/rustc_middle/src/mir/pretty.rs | 4 ++-- compiler/rustc_middle/src/thir.rs | 6 ------ compiler/rustc_mir_build/src/build/expr/as_constant.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 4 ++-- 11 files changed, 15 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index f90ad534970..0739061fdbd 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -167,7 +167,7 @@ pub(crate) fn codegen_const_value<'tcx>( } match const_val { - ConstValue::ZST => unreachable!(), // we already handles ZST above + ConstValue::Zst => unreachable!(), // we already handles ZST above ConstValue::Scalar(x) => match x { Scalar::Int(int) => { if fx.clif_type(layout.ty).is_some() { diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 72d0d3e5482..af15ae36fa9 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { let llval = bx.scalar_to_backend(x, scalar, bx.immediate_backend_type(layout)); OperandValue::Immediate(llval) } - ConstValue::ZST => { + ConstValue::Zst => { let llval = bx.zst_to_backend(bx.immediate_backend_type(layout)); OperandValue::Immediate(llval) } diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 251be589649..d3ebfd715c0 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -157,7 +157,7 @@ pub(super) fn op_to_const<'tcx>( "this MPlaceTy must come from a validated constant, thus we can assume the \ alignment is correct", ); - ConstValue::ZST + ConstValue::Zst } } }; diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 0ef55c63085..c2978e0d4f8 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -272,7 +272,7 @@ pub fn valtree_to_const_value<'tcx>( match ty.kind() { ty::FnDef(..) => { assert!(valtree.unwrap_branch().is_empty()); - ConstValue::ZST + ConstValue::Zst } ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => match valtree { ty::ValTree::Leaf(scalar_int) => ConstValue::Scalar(Scalar::Int(scalar_int)), diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index c95ae4f6e7a..236849f5f9f 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -709,7 +709,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Operand::Indirect(MemPlace::from_ptr(ptr.into())) } ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x)?.into()), - ConstValue::ZST => Operand::Immediate(Immediate::Uninit), + ConstValue::Zst => Operand::Immediate(Immediate::Uninit), ConstValue::Slice { data, start, end } => { // We rely on mutability being set correctly in `data` to prevent writes // where none should happen. diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index 59242b785c6..e38e4fc54c5 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -35,7 +35,7 @@ pub enum ConstValue<'tcx> { Scalar(Scalar), /// Only used for ZSTs. - ZST, + Zst, /// Used only for `&[u8]` and `&str` Slice { data: ConstAllocation<'tcx>, start: usize, end: usize }, @@ -58,7 +58,7 @@ impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option> { Some(match self { ConstValue::Scalar(s) => ConstValue::Scalar(s), - ConstValue::ZST => ConstValue::ZST, + ConstValue::Zst => ConstValue::Zst, ConstValue::Slice { data, start, end } => { ConstValue::Slice { data: tcx.lift(data)?, start, end } } @@ -73,7 +73,7 @@ impl<'tcx> ConstValue<'tcx> { #[inline] pub fn try_to_scalar(&self) -> Option> { match *self { - ConstValue::ByRef { .. } | ConstValue::Slice { .. } | ConstValue::ZST => None, + ConstValue::ByRef { .. } | ConstValue::Slice { .. } | ConstValue::Zst => None, ConstValue::Scalar(val) => Some(val), } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 532b7f2bf0c..066cb4d2057 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1711,7 +1711,7 @@ impl<'tcx> Operand<'tcx> { Operand::Constant(Box::new(Constant { span, user_ty: None, - literal: ConstantKind::Val(ConstValue::ZST, ty), + literal: ConstantKind::Val(ConstValue::Zst, ty), })) } @@ -2196,7 +2196,7 @@ impl<'tcx> ConstantKind<'tcx> { #[inline] pub fn zero_sized(ty: Ty<'tcx>) -> Self { - let cv = ConstValue::ZST; + let cv = ConstValue::Zst; Self::Val(cv, ty) } diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 453e33efdd2..07a3c8cf7bb 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -449,7 +449,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { } let fmt_val = |val: &ConstValue<'tcx>| match val { - ConstValue::ZST => format!("ZST"), + ConstValue::Zst => format!("ZST"), ConstValue::Scalar(s) => format!("Scalar({:?})", s), ConstValue::Slice { .. } => format!("Slice(..)"), ConstValue::ByRef { .. } => format!("ByRef(..)"), @@ -680,7 +680,7 @@ pub fn write_allocations<'tcx>( ConstValue::Scalar(interpret::Scalar::Int { .. }) => { Either::Left(Either::Right(std::iter::empty())) } - ConstValue::ZST => Either::Left(Either::Right(std::iter::empty())), + ConstValue::Zst => Either::Left(Either::Right(std::iter::empty())), ConstValue::ByRef { alloc, .. } | ConstValue::Slice { data: alloc, .. } => { Either::Right(alloc_ids_from_alloc(alloc)) } diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 1938c56768d..3fe6394ad7e 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -458,12 +458,6 @@ pub enum ExprKind<'tcx> { }, } -impl<'tcx> ExprKind<'tcx> { - pub fn zero_sized_literal(user_ty: Option>>) -> Self { - ExprKind::ZstLiteral { user_ty } - } -} - /// Represents the association of a field identifier and an expression. /// /// This is used in struct constructors. diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index c3af9f2d2b7..063500c9187 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -61,7 +61,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { inferred_ty: ty, }) }); - let literal = ConstantKind::Val(ConstValue::ZST, ty); + let literal = ConstantKind::Val(ConstValue::Zst, ty); Constant { span, user_ty: user_ty, literal } } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 4bc3d216a40..4eb3607e9cc 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -799,7 +799,7 @@ impl<'tcx> Cx<'tcx> { } }; let ty = self.tcx().mk_fn_def(def_id, substs); - Expr { temp_lifetime, ty, span, kind: ExprKind::zero_sized_literal(user_ty) } + Expr { temp_lifetime, ty, span, kind: ExprKind::ZstLiteral { user_ty } } } fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId { @@ -828,7 +828,7 @@ impl<'tcx> Cx<'tcx> { | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(_) => { let user_ty = self.user_substs_applied_to_res(expr.hir_id, res); - ExprKind::zero_sized_literal(user_ty) + ExprKind::ZstLiteral { user_ty } } Res::Def(DefKind::ConstParam, def_id) => {