]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_const_eval/src/interpret/step.rs
require full validity when determining the discriminant of a value
[rust.git] / compiler / rustc_const_eval / src / interpret / step.rs
index e6037d561dedcb5228ed84e93e524df136f17551..2759a7d9d268f75d752fa79aef435b64f588389d 100644 (file)
@@ -304,6 +304,12 @@ pub fn eval_rvalue_into_place(
 
             Discriminant(place) => {
                 let op = self.eval_place_to_op(place, None)?;
+                if M::enforce_validity(self) {
+                    // This is 'using' the value, so make sure the validity invariant is satisfied.
+                    // (Also see https://github.com/rust-lang/rust/pull/89764.)
+                    self.validate_operand(&op)?;
+                }
+
                 let discr_val = self.read_discriminant(&op)?.0;
                 self.write_scalar(discr_val, &dest)?;
             }