Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8282d52

Browse files
committed
Replace Scalar::zst with a Scalar::ZST constant
1 parent b8751c1 commit 8282d52

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

compiler/rustc_middle/src/mir/interpret/value.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ impl<'tcx, Tag> Scalar<Tag> {
178178
Scalar::Int(ScalarInt::null(cx.data_layout().pointer_size))
179179
}
180180

181-
#[inline]
182-
pub fn zst() -> Self {
183-
Scalar::Int(ScalarInt::ZST)
184-
}
181+
pub const ZST: Self = Scalar::Int(ScalarInt::ZST);
185182

186183
#[inline(always)]
187184
fn ptr_op(

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'tcx> Const<'tcx> {
132132
#[inline]
133133
/// Creates an interned zst constant.
134134
pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx Self {
135-
Self::from_scalar(tcx, Scalar::zst(), ty)
135+
Self::from_scalar(tcx, Scalar::ZST, ty)
136136
}
137137

138138
#[inline]

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ impl<'tcx> CommonConsts<'tcx> {
844844

845845
CommonConsts {
846846
unit: mk_const(ty::Const {
847-
val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::zst())),
847+
val: ty::ConstKind::Value(ConstValue::Scalar(Scalar::ZST)),
848848
ty: types.unit,
849849
}),
850850
}

compiler/rustc_mir/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub(super) fn op_to_const<'tcx>(
146146
"this MPlaceTy must come from a validated constant, thus we can assume the \
147147
alignment is correct",
148148
);
149-
ConstValue::Scalar(Scalar::zst())
149+
ConstValue::Scalar(Scalar::ZST)
150150
}
151151
};
152152
match immediate {

compiler/rustc_mir/src/interpret/operand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
259259
}
260260
return Ok(Some(ImmTy {
261261
// zero-sized type
262-
imm: Scalar::zst().into(),
262+
imm: Scalar::ZST.into(),
263263
layout: mplace.layout,
264264
}));
265265
}
@@ -358,7 +358,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
358358

359359
let field_layout = op.layout.field(self, field)?;
360360
if field_layout.is_zst() {
361-
let immediate = Scalar::zst().into();
361+
let immediate = Scalar::ZST.into();
362362
return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout });
363363
}
364364
let offset = op.layout.fields.offset(field);
@@ -443,7 +443,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
443443
let layout = self.layout_of_local(frame, local, layout)?;
444444
let op = if layout.is_zst() {
445445
// Do not read from ZST, they might not be initialized
446-
Operand::Immediate(Scalar::zst().into())
446+
Operand::Immediate(Scalar::ZST.into())
447447
} else {
448448
M::access_local(&self, frame, local)?
449449
};

0 commit comments

Comments
 (0)