diff options
| author | bors <bors@rust-lang.org> | 2022-03-22 19:06:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-22 19:06:04 +0000 |
| commit | 5f37001055c29982f4c27ee9edd90449c8e07774 (patch) | |
| tree | d8897f02157dc621ff21fa007dbd082e6aed28f0 /compiler/rustc_const_eval/src/interpret/eval_context.rs | |
| parent | 64137f0b15b752d0c734661dc713bcd140858320 (diff) | |
| parent | 2aca599325021f352f9bff06fa42daeb3c4bd4f8 (diff) | |
Auto merge of #95215 - Dylan-DPC:rollup-l9f9t7l, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #95188 ([`macro-metavar-expr`] Fix generated tokens hygiene) - #95196 (rename LocalState::Uninitialized to Unallocated) - #95197 (Suggest constraining param for unary ops when missing trait impl) - #95200 (Cancel a not emitted error after parsing const generic args) - #95207 (update Termination trait docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/eval_context.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/eval_context.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index a8a57e6990f..d78c7a9fad9 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -177,11 +177,10 @@ pub struct LocalState<'tcx, Tag: Provenance = AllocId> { pub enum LocalValue<Tag: Provenance = AllocId> { /// This local is not currently alive, and cannot be used at all. Dead, - /// This local is alive but not yet initialized. It can be written to - /// but not read from or its address taken. Locals get initialized on - /// first write because for unsized locals, we do not know their size - /// before that. - Uninitialized, + /// This local is alive but not yet allocated. It cannot be read from or have its address taken, + /// and will be allocated on the first write. This is to support unsized locals, where we cannot + /// know their size in advance. + Unallocated, /// A normal, live local. /// Mostly for convenience, we re-use the `Operand` type here. /// This is an optimization over just always having a pointer here; @@ -198,7 +197,7 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> { pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> { match self.value { LocalValue::Dead => throw_ub!(DeadLocal), - LocalValue::Uninitialized => { + LocalValue::Unallocated => { bug!("The type checker should prevent reading from a never-written local") } LocalValue::Live(val) => Ok(val), @@ -216,8 +215,7 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> { match self.value { LocalValue::Dead => throw_ub!(DeadLocal), LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)), - ref mut - local @ (LocalValue::Live(Operand::Immediate(_)) | LocalValue::Uninitialized) => { + ref mut local @ (LocalValue::Live(Operand::Immediate(_)) | LocalValue::Unallocated) => { Ok(Ok(local)) } } @@ -752,8 +750,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { })?; } - // Locals are initially uninitialized. - let dummy = LocalState { value: LocalValue::Uninitialized, layout: Cell::new(None) }; + // Locals are initially unallocated. + let dummy = LocalState { value: LocalValue::Unallocated, layout: Cell::new(None) }; let mut locals = IndexVec::from_elem(dummy, &body.local_decls); // Now mark those locals as dead that we do not want to initialize @@ -921,7 +919,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { assert!(local != mir::RETURN_PLACE, "Cannot make return place live"); trace!("{:?} is now live", local); - let local_val = LocalValue::Uninitialized; + let local_val = LocalValue::Unallocated; // StorageLive expects the local to be dead, and marks it live. let old = mem::replace(&mut self.frame_mut().locals[local].value, local_val); if !matches!(old, LocalValue::Dead) { @@ -1025,7 +1023,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> std::fmt::Debug match self.ecx.stack()[frame].locals[local].value { LocalValue::Dead => write!(fmt, " is dead")?, - LocalValue::Uninitialized => write!(fmt, " is uninitialized")?, + LocalValue::Unallocated => write!(fmt, " is unallocated")?, LocalValue::Live(Operand::Indirect(mplace)) => { write!( fmt, |
