From 4920a3371f5c02e61d3a0f5722ff7034a99938ff Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 25 Mar 2020 08:46:58 +0100 Subject: [PATCH 1/2] better explain GLOBAL_KIND choice --- src/librustc_mir/const_eval/machine.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/const_eval/machine.rs b/src/librustc_mir/const_eval/machine.rs index 8f4501cc3fb69..3f657089251e4 100644 --- a/src/librustc_mir/const_eval/machine.rs +++ b/src/librustc_mir/const_eval/machine.rs @@ -178,7 +178,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter { type MemoryMap = FxHashMap, Allocation)>; - const GLOBAL_KIND: Option = None; // no copying of globals allowed + const GLOBAL_KIND: Option = None; // no copying of globals from `tcx` to machine memory // We do not check for alignment to avoid having to carry an `Align` // in `ConstValue::ByRef`. diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index cbb79637076bc..232d33a35313e 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -172,7 +172,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { type MemoryMap = FxHashMap, Allocation)>; - const GLOBAL_KIND: Option = None; + const GLOBAL_KIND: Option = None; // no copying of globals from `tcx` to machine memory const CHECK_ALIGN: bool = false; From b5343d6baa6daeca974931f4148638393e80e216 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 25 Mar 2020 08:47:59 +0100 Subject: [PATCH 2/2] rename def_id -> static_def_id --- src/librustc_mir/const_eval/machine.rs | 6 +++--- src/librustc_mir/interpret/machine.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/const_eval/machine.rs b/src/librustc_mir/const_eval/machine.rs index 3f657089251e4..0970e09791999 100644 --- a/src/librustc_mir/const_eval/machine.rs +++ b/src/librustc_mir/const_eval/machine.rs @@ -350,15 +350,15 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter { memory_extra: &MemoryExtra, alloc_id: AllocId, allocation: &Allocation, - def_id: Option, + static_def_id: Option, is_write: bool, ) -> InterpResult<'tcx> { if is_write && allocation.mutability == Mutability::Not { Err(err_ub!(WriteToReadOnly(alloc_id)).into()) } else if is_write { Err(ConstEvalErrKind::ModifiedGlobal.into()) - } else if memory_extra.can_access_statics || def_id.is_none() { - // `def_id.is_none()` indicates this is not a static, but a const or so. + } else if memory_extra.can_access_statics || static_def_id.is_none() { + // `static_def_id.is_none()` indicates this is not a static, but a const or so. Ok(()) } else { Err(ConstEvalErrKind::ConstAccessesStatic.into()) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index cc87c2916862b..74933bed8f89e 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -215,7 +215,7 @@ pub trait Machine<'mir, 'tcx>: Sized { _memory_extra: &Self::MemoryExtra, _alloc_id: AllocId, _allocation: &Allocation, - _def_id: Option, + _static_def_id: Option, _is_write: bool, ) -> InterpResult<'tcx> { Ok(()) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 232d33a35313e..3b2a41e5c0cfc 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -274,7 +274,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { _memory_extra: &(), _alloc_id: AllocId, allocation: &Allocation, - def_id: Option, + static_def_id: Option, is_write: bool, ) -> InterpResult<'tcx> { if is_write { @@ -285,7 +285,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { 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 { + if static_def_id.is_some() && allocation.relocations().len() > 0 { throw_machine_stop_str!("can't eval statics with pointers in ConstProp"); }