From 1939b4c940be8569eadbb556e3987534a3d26594 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 24 Mar 2020 14:31:55 +0100 Subject: [PATCH] actually we can reject all reads from mutable allocs in const-prop --- src/librustc_mir/transform/const_prop.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index ef2d5404541b9..6f3cdfdcd7e24 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -282,12 +282,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { } // If the static allocation is mutable or if it has relocations (it may be legal to mutate // the memory behind that in the future), then we can't const prop it. - // FIXME: we only check statics here (that have a `DefId`), not other mutable allocations. - // Why that? - if def_id.is_some() - && (allocation.mutability == Mutability::Mut || allocation.relocations().len() > 0) - { - throw_machine_stop_str!("can't eval mutable statics in ConstProp"); + if allocation.mutability == Mutability::Mut { + throw_machine_stop_str!("can't eval mutable globals in ConstProp"); + } + if def_id.is_some() && allocation.relocations().len() > 0 { + throw_machine_stop_str!("can't eval statics with pointers in ConstProp"); } Ok(())