Skip to content

Commit c7023d1

Browse files
committed
run MIR borrowck on the validated, not optimized, MIR
1 parent 74b2783 commit c7023d1

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'hir> Map<'hir> {
455455
if let EntryExpr(_, expr) = entry {
456456
BodyId { node_id: expr.id }
457457
} else {
458-
span_bug!(self.span(id), "id `{}` has no associated body", id);
458+
span_bug!(self.span(id), "id `{}` has no associated body: {:?}", id, entry);
459459
}
460460
}
461461
} else {

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ pub fn borrowck_mir(bcx: &mut BorrowckCtxt,
6161
let def_id = tcx.hir.local_def_id(id);
6262
debug!("borrowck_mir({}) UNIMPLEMENTED", tcx.item_path_str(def_id));
6363

64-
let mir = &tcx.item_mir(def_id);
64+
// It is safe for us to borrow `mir_validated()`: `optimized_mir`
65+
// steals it, but it forces the `borrowck` query.
66+
let mir = &tcx.mir_validated(def_id).borrow();
67+
6568
let param_env = ty::ParameterEnvironment::for_item(tcx, id);
6669
let move_data = MoveData::gather_moves(mir, tcx, &param_env);
6770
let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env };

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
8686
debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
8787

8888
let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
89+
90+
match tcx.hir.get(owner_id) {
91+
hir_map::NodeStructCtor(_) |
92+
hir_map::NodeVariant(_) => {
93+
// We get invoked with anything that has MIR, but some of
94+
// those things (notably the synthesized constructors from
95+
// tuple structs/variants) do not have an associated body
96+
// and do not need borrowchecking.
97+
return;
98+
}
99+
_ => { }
100+
}
101+
89102
let body_id = tcx.hir.body_owned_by(owner_id);
90103
let attributes = tcx.get_attrs(owner_def_id);
91104
let tables = tcx.typeck_tables_of(owner_def_id);

src/librustc_mir/queries.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
110110
}
111111

112112
fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> {
113+
// Borrowck uses `mir_validated`, so we have to force it to
114+
// execute before we can steal.
115+
ty::queries::borrowck::force(tcx, DUMMY_SP, def_id);
116+
113117
let mut mir = tcx.mir_validated(def_id).steal();
114118
let source = MirSource::from_local_def_id(tcx, def_id);
115119
transform::run_suite(tcx, source, MIR_OPTIMIZED, &mut mir);

0 commit comments

Comments
 (0)