Auto merge of #125923 - matthewjasper:no-return-leak, r= · rust-lang/rust@1c34390 (original) (raw)

`@@ -20,6 +20,8 @@ use rustc_middle::ty::{self, Ty, UpvarArgs};

`

20

20

`use rustc_span::{Span, DUMMY_SP};

`

21

21

`use tracing::debug;

`

22

22

``

``

23

`+

use std::slice;

`

``

24

+

23

25

`impl<'a, 'tcx> Builder<'a, 'tcx> {

`

24

26

`/// Returns an rvalue suitable for use until the end of the current

`

25

27

`/// scope expression.

`

`@@ -183,15 +185,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

`

183

185

`let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value_ty);

`

184

186

` this.cfg.push_assign(block, source_info, Place::from(result), box_);

`

185

187

``

186

``

`-

// initialize the box contents:

`

``

188

`+

// Initialize the box contents. No scope is needed since the

`

``

189

`` +

// Box is already scheduled to be dropped.

``

187

190

`unpack!(

`

188

191

` block = this.expr_into_dest(

`

189

192

` this.tcx.mk_place_deref(Place::from(result)),

`

``

193

`+

None,

`

190

194

` block,

`

191

195

` value,

`

192

196

`)

`

193

197

`);

`

194

``

`-

block.and(Rvalue::Use(Operand::Move(Place::from(result))))

`

``

198

`+

let result_operand = Operand::Move(Place::from(result));

`

``

199

`+

this.record_operands_moved(slice::from_ref(&result_operand));

`

``

200

`+

block.and(Rvalue::Use(result_operand))

`

195

201

`}

`

196

202

`ExprKind::Cast { source } => {

`

197

203

`let source_expr = &this.thir[source];

`

`@@ -359,6 +365,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

`

359

365

`})

`

360

366

`.collect();

`

361

367

``

``

368

`+

this.record_operands_moved(&fields.raw);

`

362

369

` block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(el_ty)), fields))

`

363

370

`}

`

364

371

`ExprKind::Tuple { ref fields } => {

`

`@@ -380,6 +387,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

`

380

387

`})

`

381

388

`.collect();

`

382

389

``

``

390

`+

this.record_operands_moved(&fields.raw);

`

383

391

` block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))

`

384

392

`}

`

385

393

`ExprKind::Closure(box ClosureExpr {

`

`@@ -482,6 +490,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

`

482

490

`Box::new(AggregateKind::CoroutineClosure(closure_id.to_def_id(), args))

`

483

491

`}

`

484

492

`};

`

``

493

`+

this.record_operands_moved(&operands.raw);

`

485

494

` block.and(Rvalue::Aggregate(result, operands))

`

486

495

`}

`

487

496

`ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {

`

`@@ -737,7 +746,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

`

737

746

` this.diverge_from(block);

`

738

747

` block = success;

`

739

748

`}

`

740

``

`-

this.record_operands_moved(&[Spanned { node: value_operand, span: DUMMY_SP }]);

`

``

749

`+

this.record_operands_moved(&[value_operand]);

`

741

750

`}

`

742

751

` block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new()))

`

743

752

`}

`