Skip to content

Commit 498ebc4

Browse files
committed
require full validity when determining the discriminant of a value
1 parent 1b12d01 commit 498ebc4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
265265
}
266266
sym::discriminant_value => {
267267
let place = self.deref_operand(&args[0])?;
268+
if M::enforce_validity(self) {
269+
// This is 'using' the value, so make sure the validity invariant is satisfied.
270+
// (Also see https://github.com/rust-lang/rust/pull/89764.)
271+
self.validate_operand(&place.into())?;
272+
}
273+
268274
let discr_val = self.read_discriminant(&place.into())?.0;
269275
self.write_scalar(discr_val, dest)?;
270276
}

compiler/rustc_const_eval/src/interpret/step.rs

+6
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
304304

305305
Discriminant(place) => {
306306
let op = self.eval_place_to_op(place, None)?;
307+
if M::enforce_validity(self) {
308+
// This is 'using' the value, so make sure the validity invariant is satisfied.
309+
// (Also see https://github.com/rust-lang/rust/pull/89764.)
310+
self.validate_operand(&op)?;
311+
}
312+
307313
let discr_val = self.read_discriminant(&op)?.0;
308314
self.write_scalar(discr_val, &dest)?;
309315
}

0 commit comments

Comments
 (0)