diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-01-18 09:11:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-18 09:11:03 +0100 |
| commit | dbc27cac27205609f285beb88f2da65a5ea2b506 (patch) | |
| tree | ee4024425858df36e44549e8d8d033a16bcfde86 | |
| parent | 8e59cf95d540fcb341790126f524754f45a198ad (diff) | |
| parent | fc9a14d31a5b79bccfbc7d64e64163ddbb8a4a06 (diff) | |
| download | rust-dbc27cac27205609f285beb88f2da65a5ea2b506.tar.gz rust-dbc27cac27205609f285beb88f2da65a5ea2b506.zip | |
Rollup merge of #134455 - lcnr:move-errors-in-promoteds, r=compiler-errors
cleanup promoteds move check r? types
| -rw-r--r-- | compiler/rustc_borrowck/src/lib.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 45764f9c6b8..c6e6d962ce5 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -182,9 +182,6 @@ fn do_mir_borrowck<'tcx>( let location_table = PoloniusLocationTable::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")) @@ -242,10 +239,14 @@ 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]; + // This assumes that we won't use some of the fields of the `promoted_mbcx` + // when detecting and reporting move errors. While it would be nice to move + // this check out of `MirBorrowckCtxt`, actually doing so is far from trivial. + let move_data = MoveData::gather_moves(promoted_body, tcx, |_| true); let mut promoted_mbcx = MirBorrowckCtxt { infcx: &infcx, body: promoted_body, @@ -270,9 +271,6 @@ fn do_mir_borrowck<'tcx>( move_errors: Vec::new(), diags_buffer, }; - 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>, } @@ -284,6 +282,8 @@ fn do_mir_borrowck<'tcx>( } } } + MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body); + promoted_mbcx.report_move_errors(); } let mut mbcx = MirBorrowckCtxt { |
