Skip to content

Commit 38c0887

Browse files
committed
Fix remaining Body -> (ReadOnly)BodyCache type errors in librustc_mir outside of librustc_mir/transform
1 parent 3642a71 commit 38c0887

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/librustc_mir/shim.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,23 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
202202
sig.inputs().len(),
203203
span);
204204

205+
let mut body_cache = BodyCache::new(&mut body);
206+
205207
if let Some(..) = ty {
206208
// The first argument (index 0), but add 1 for the return value.
207209
let dropee_ptr = Place::from(Local::new(1+0));
208210
if tcx.sess.opts.debugging_opts.mir_emit_retag {
209211
// Function arguments should be retagged, and we make this one raw.
210-
body.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
212+
body_cache.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
211213
source_info,
212214
kind: StatementKind::Retag(RetagKind::Raw, box(dropee_ptr.clone())),
213215
});
214216
}
215217
let patch = {
216218
let param_env = tcx.param_env(def_id).with_reveal_all();
217219
let mut elaborator = DropShimElaborator {
218-
body: &body,
219-
patch: MirPatch::new(&body),
220+
body: body_cache.body(),
221+
patch: MirPatch::new(body_cache.body()),
220222
tcx,
221223
param_env
222224
};
@@ -233,9 +235,10 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
233235
);
234236
elaborator.patch
235237
};
236-
patch.apply(&mut body);
238+
patch.apply(&mut body_cache);
237239
}
238240

241+
// TODO(pfaia) return owning body cache...
239242
body
240243
}
241244

src/librustc_mir/util/def_use.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Def-use analysis.
22
3-
use rustc::mir::{Body, Local, Location, PlaceElem, VarDebugInfo};
3+
use rustc::mir::{Body, BodyCache, Local, Location, PlaceElem, ReadOnlyBodyCache, VarDebugInfo};
44
use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor};
55
use rustc::ty::TyCtxt;
66
use rustc_index::vec::IndexVec;
@@ -30,15 +30,15 @@ impl DefUseAnalysis {
3030
}
3131
}
3232

33-
pub fn analyze(&mut self, body: &Body<'_>) {
33+
pub fn analyze(&mut self, body_cache: &ReadOnlyBodyCache<'_, '_>) {
3434
self.clear();
3535

3636
let mut finder = DefUseFinder {
3737
info: mem::take(&mut self.info),
3838
var_debug_info_index: 0,
3939
in_var_debug_info: false,
4040
};
41-
finder.visit_body(body);
41+
finder.visit_body(body_cache);
4242
self.info = finder.info
4343
}
4444

@@ -55,28 +55,28 @@ impl DefUseAnalysis {
5555
fn mutate_defs_and_uses(
5656
&self,
5757
local: Local,
58-
body: &mut Body<'tcx>,
58+
body_cache: &mut BodyCache<&mut Body<'tcx>>,
5959
new_local: Local,
6060
tcx: TyCtxt<'tcx>,
6161
) {
62-
let mut visitor = MutateUseVisitor::new(local, new_local, body, tcx);
62+
let mut visitor = MutateUseVisitor::new(local, new_local, tcx);
6363
let info = &self.info[local];
6464
for place_use in &info.defs_and_uses {
65-
visitor.visit_location(body, place_use.location)
65+
visitor.visit_location(body_cache, place_use.location)
6666
}
6767
// Update debuginfo as well, alongside defs/uses.
6868
for &i in &info.var_debug_info_indices {
69-
visitor.visit_var_debug_info(&mut body.var_debug_info[i]);
69+
visitor.visit_var_debug_info(&mut body_cache.var_debug_info[i]);
7070
}
7171
}
7272

7373
// FIXME(pcwalton): this should update the def-use chains.
7474
pub fn replace_all_defs_and_uses_with(&self,
7575
local: Local,
76-
body: &mut Body<'tcx>,
76+
body_cache: &mut BodyCache<&mut Body<'tcx>>,
7777
new_local: Local,
7878
tcx: TyCtxt<'tcx>) {
79-
self.mutate_defs_and_uses(local, body, new_local, tcx)
79+
self.mutate_defs_and_uses(local, body_cache, new_local, tcx)
8080
}
8181
}
8282

@@ -156,7 +156,6 @@ impl MutateUseVisitor<'tcx> {
156156
fn new(
157157
query: Local,
158158
new_local: Local,
159-
_: &Body<'tcx>,
160159
tcx: TyCtxt<'tcx>,
161160
) -> MutateUseVisitor<'tcx> {
162161
MutateUseVisitor { query, new_local, tcx }

0 commit comments

Comments
 (0)