Skip to content

Commit 1939b4c

Browse files
committed
actually we can reject all reads from mutable allocs in const-prop
1 parent 7a73b87 commit 1939b4c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/librustc_mir/transform/const_prop.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
282282
}
283283
// If the static allocation is mutable or if it has relocations (it may be legal to mutate
284284
// the memory behind that in the future), then we can't const prop it.
285-
// FIXME: we only check statics here (that have a `DefId`), not other mutable allocations.
286-
// Why that?
287-
if def_id.is_some()
288-
&& (allocation.mutability == Mutability::Mut || allocation.relocations().len() > 0)
289-
{
290-
throw_machine_stop_str!("can't eval mutable statics in ConstProp");
285+
if allocation.mutability == Mutability::Mut {
286+
throw_machine_stop_str!("can't eval mutable globals in ConstProp");
287+
}
288+
if def_id.is_some() && allocation.relocations().len() > 0 {
289+
throw_machine_stop_str!("can't eval statics with pointers in ConstProp");
291290
}
292291

293292
Ok(())

0 commit comments

Comments
 (0)