Skip to content

Commit 175c8cb

Browse files
authored
Rollup merge of rust-lang#86362 - ptrojahn:insert_vars_and_temps, r=jackh726
Avoid cloning LocalDecls
2 parents e7a247d + 7bcc9ae commit 175c8cb

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

compiler/rustc_middle/src/mir/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ impl<'tcx> Body<'tcx> {
426426
(arg_count + 1..local_count).map(Local::new)
427427
}
428428

429+
#[inline]
430+
pub fn drain_vars_and_temps<'a>(&'a mut self) -> impl Iterator<Item = LocalDecl<'tcx>> + 'a {
431+
self.local_decls.drain(self.arg_count + 1..)
432+
}
433+
429434
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
430435
/// invalidating statement indices in `Location`s.
431436
pub fn make_statement_nop(&mut self, location: Location) {

compiler/rustc_mir/src/transform/inline.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,7 @@ impl Inliner<'tcx> {
607607
}
608608

609609
// Insert all of the (mapped) parts of the callee body into the caller.
610-
caller_body.local_decls.extend(
611-
// FIXME(eddyb) make `Range<Local>` iterable so that we can use
612-
// `callee_body.local_decls.drain(callee_body.vars_and_temps())`
613-
callee_body
614-
.vars_and_temps_iter()
615-
.map(|local| callee_body.local_decls[local].clone()),
616-
);
610+
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
617611
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
618612
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
619613
caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));

0 commit comments

Comments
 (0)