Skip to content

Commit 06ca7b7

Browse files
committed
validate promoteds
1 parent bd2f1cb commit 06ca7b7

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

compiler/rustc_mir/src/const_eval/eval_queries.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -383,25 +383,15 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
383383
Ok(mplace) => {
384384
// Since evaluation had no errors, valiate the resulting constant:
385385
let validation = try {
386-
// FIXME do not validate promoteds until a decision on
387-
// https://github.com/rust-lang/rust/issues/67465 and
388-
// https://github.com/rust-lang/rust/issues/67534 is made.
389-
// Promoteds can contain unexpected `UnsafeCell` and reference `static`s, but their
390-
// otherwise restricted form ensures that this is still sound. We just lose the
391-
// extra safety net of some of the dynamic checks. They can also contain invalid
392-
// values, but since we do not usually check intermediate results of a computation
393-
// for validity, it might be surprising to do that here.
394-
if cid.promoted.is_none() {
395-
let mut ref_tracking = RefTracking::new(mplace);
396-
let mut inner = false;
397-
while let Some((mplace, path)) = ref_tracking.todo.pop() {
398-
let mode = match tcx.static_mutability(cid.instance.def_id()) {
399-
Some(_) => CtfeValidationMode::Regular, // a `static`
400-
None => CtfeValidationMode::Const { inner },
401-
};
402-
ecx.const_validate_operand(mplace.into(), path, &mut ref_tracking, mode)?;
403-
inner = true;
404-
}
386+
let mut ref_tracking = RefTracking::new(mplace);
387+
let mut inner = false;
388+
while let Some((mplace, path)) = ref_tracking.todo.pop() {
389+
let mode = match tcx.static_mutability(cid.instance.def_id()) {
390+
Some(_) if cid.promoted.is_none() => CtfeValidationMode::Regular, // a `static`
391+
_ => CtfeValidationMode::Const { inner },
392+
};
393+
ecx.const_validate_operand(mplace.into(), path, &mut ref_tracking, mode)?;
394+
inner = true;
405395
}
406396
};
407397
if let Err(error) = validation {

0 commit comments

Comments
 (0)