1
Fork 0

validate promoteds

This commit is contained in:
Ralf Jung 2020-12-20 15:49:08 +01:00
parent bd2f1cb278
commit 06ca7b700c

View file

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