Skip to content

Commit

Permalink
cleanup promoteds move check
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Dec 18, 2024
1 parent 37e7459 commit f936122
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ fn do_mir_borrowck<'tcx>(
let location_table = LocationTable::new(body);

let move_data = MoveData::gather_moves(body, tcx, |_| true);
let promoted_move_data = promoted
.iter_enumerated()
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, |_| true)));

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

for (idx, move_data) in promoted_move_data {
// While promoteds should mostly be correct by construction, we need to check them for
// invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
for promoted_body in &promoted {
use rustc_middle::mir::visit::Visitor;

let promoted_body = &promoted[idx];
// FIXME: This assumes that we don't try to access most fields of the `promoted_mbcx`.
// We may want to move `MoveError` construction and reporting out of `MirBorrowckCtxt`.
let move_data = MoveData::gather_moves(body, tcx, |_| true);
let mut promoted_mbcx = MirBorrowckCtxt {
infcx: &infcx,
body: promoted_body,
Expand All @@ -262,9 +262,6 @@ fn do_mir_borrowck<'tcx>(
move_errors: Vec::new(),
diags,
};
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
promoted_mbcx.report_move_errors();

struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
}
Expand All @@ -276,6 +273,8 @@ fn do_mir_borrowck<'tcx>(
}
}
}
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
promoted_mbcx.report_move_errors();
}

let mut mbcx = MirBorrowckCtxt {
Expand Down

0 comments on commit f936122

Please sign in to comment.