diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 376ce3b239f9..dfdd95c95a36 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -251,7 +251,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// `canonical_alloc_id` would result in pointer pointing to `t2`'s thread /// local and not `t1` as it should. #[inline] - fn eval_maybe_thread_local_static_const( + fn adjust_global_const( _ecx: &InterpCx<'mir, 'tcx, Self>, val: mir::interpret::ConstValue<'tcx>, ) -> InterpResult<'tcx, mir::interpret::ConstValue<'tcx>> { diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index df9ce3f18a9f..450d5500cfd5 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -537,7 +537,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } ty::ConstKind::Value(val_val) => val_val, }; - let val_val = M::eval_maybe_thread_local_static_const(self, val_val)?; + // This call allows the machine to create fresh allocation ids for + // thread-local statics (see the `adjust_global_const` function + // documentation). Please note that the `const_eval` call in the early + // return above calls `eval_const_to_op` again, so `adjust_global_const` + // is guaranteed to be called for all constants. + let val_val = M::adjust_global_const(self, val_val)?; // Other cases need layout. let layout = from_known_layout(self.tcx, layout, || self.layout_of(val.ty))?; let op = match val_val {