Skip to content

Commit f936122

Browse files
committed
cleanup promoteds move check
1 parent 37e7459 commit f936122

File tree

1 file changed

+8
-9
lines changed
  • compiler/rustc_borrowck/src

1 file changed

+8
-9
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ fn do_mir_borrowck<'tcx>(
183183
let location_table = LocationTable::new(body);
184184

185185
let move_data = MoveData::gather_moves(body, tcx, |_| true);
186-
let promoted_move_data = promoted
187-
.iter_enumerated()
188-
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, |_| true)));
189186

190187
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
191188
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
@@ -235,10 +232,13 @@ fn do_mir_borrowck<'tcx>(
235232
false
236233
};
237234

238-
for (idx, move_data) in promoted_move_data {
235+
// While promoteds should mostly be correct by construction, we need to check them for
236+
// invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
237+
for promoted_body in &promoted {
239238
use rustc_middle::mir::visit::Visitor;
240-
241-
let promoted_body = &promoted[idx];
239+
// FIXME: This assumes that we don't try to access most fields of the `promoted_mbcx`.
240+
// We may want to move `MoveError` construction and reporting out of `MirBorrowckCtxt`.
241+
let move_data = MoveData::gather_moves(body, tcx, |_| true);
242242
let mut promoted_mbcx = MirBorrowckCtxt {
243243
infcx: &infcx,
244244
body: promoted_body,
@@ -262,9 +262,6 @@ fn do_mir_borrowck<'tcx>(
262262
move_errors: Vec::new(),
263263
diags,
264264
};
265-
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
266-
promoted_mbcx.report_move_errors();
267-
268265
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
269266
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
270267
}
@@ -276,6 +273,8 @@ fn do_mir_borrowck<'tcx>(
276273
}
277274
}
278275
}
276+
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
277+
promoted_mbcx.report_move_errors();
279278
}
280279

281280
let mut mbcx = MirBorrowckCtxt {

0 commit comments

Comments
 (0)