Skip to content

Commit f5ab92c

Browse files
authored
Rollup merge of rust-lang#147868 - cjgillot:patch-local, r=saethlin
MirPatch: Simplify new_local. Small simplification.
2 parents 7a9faf0 + a1e42f9 commit f5ab92c

File tree

1 file changed

+6
-6
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+6
-6
lines changed

compiler/rustc_mir_transform/src/patch.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub(crate) struct MirPatch<'tcx> {
2424
// Cached block for UnwindTerminate (with reason)
2525
terminate_block: Option<(BasicBlock, UnwindTerminateReason)>,
2626
body_span: Span,
27+
/// The number of locals at the start of the transformation. New locals
28+
/// get appended at the end.
2729
next_local: usize,
2830
/// The number of blocks at the start of the transformation. New blocks
2931
/// get appended at the end.
@@ -176,8 +178,7 @@ impl<'tcx> MirPatch<'tcx> {
176178
span: Span,
177179
local_info: LocalInfo<'tcx>,
178180
) -> Local {
179-
let index = self.next_local;
180-
self.next_local += 1;
181+
let index = self.next_local + self.new_locals.len();
181182
let mut new_decl = LocalDecl::new(ty, span);
182183
**new_decl.local_info.as_mut().unwrap_crate_local() = local_info;
183184
self.new_locals.push(new_decl);
@@ -186,17 +187,16 @@ impl<'tcx> MirPatch<'tcx> {
186187

187188
/// Queues the addition of a new temporary.
188189
pub(crate) fn new_temp(&mut self, ty: Ty<'tcx>, span: Span) -> Local {
189-
let index = self.next_local;
190-
self.next_local += 1;
190+
let index = self.next_local + self.new_locals.len();
191191
self.new_locals.push(LocalDecl::new(ty, span));
192192
Local::new(index)
193193
}
194194

195195
/// Returns the type of a local that's newly-added in the patch.
196196
pub(crate) fn local_ty(&self, local: Local) -> Ty<'tcx> {
197197
let local = local.as_usize();
198-
assert!(local < self.next_local);
199-
let new_local_idx = self.new_locals.len() - (self.next_local - local);
198+
assert!(local < self.next_local + self.new_locals.len());
199+
let new_local_idx = local - self.next_local;
200200
self.new_locals[new_local_idx].ty
201201
}
202202

0 commit comments

Comments
 (0)