cleanup promoteds move check · rust-lang/rust@fc9a14d (original) (raw)

`@@ -183,9 +183,6 @@ fn do_mir_borrowck<'tcx>(

`

183

183

`let location_table = LocationTable::new(body);

`

184

184

``

185

185

`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)));

`

189

186

``

190

187

`let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)

`

191

188

`.iterate_to_fixpoint(tcx, body, Some("borrowck"))

`

`@@ -235,10 +232,14 @@ fn do_mir_borrowck<'tcx>(

`

235

232

`false

`

236

233

`};

`

237

234

``

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 {

`

239

238

`use rustc_middle::mir::visit::Visitor;

`

240

``

-

241

``

`-

let promoted_body = &promoted[idx];

`

``

239

`` +

// This assumes that we won't use some of the fields of the promoted_mbcx

``

``

240

`+

// when detecting and reporting move errors. While it would be nice to move

`

``

241

`` +

// this check out of MirBorrowckCtxt, actually doing so is far from trivial.

``

``

242

`+

let move_data = MoveData::gather_moves(promoted_body, tcx, |_| true);

`

242

243

`let mut promoted_mbcx = MirBorrowckCtxt {

`

243

244

`infcx: &infcx,

`

244

245

`body: promoted_body,

`

`@@ -262,9 +263,6 @@ fn do_mir_borrowck<'tcx>(

`

262

263

`move_errors: Vec::new(),

`

263

264

` diags,

`

264

265

`};

`

265

``

`-

MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);

`

266

``

`-

promoted_mbcx.report_move_errors();

`

267

``

-

268

266

`struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {

`

269

267

`ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,

`

270

268

`}

`

`@@ -276,6 +274,8 @@ fn do_mir_borrowck<'tcx>(

`

276

274

`}

`

277

275

`}

`

278

276

`}

`

``

277

`+

MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);

`

``

278

`+

promoted_mbcx.report_move_errors();

`

279

279

`}

`

280

280

``

281

281

`let mut mbcx = MirBorrowckCtxt {

`