Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7216012

Browse files
committed
Inject fake read in binding pattern
1 parent f004cae commit 7216012

File tree

1 file changed

+13
-0
lines changed
  • src/librustc_mir/build/matches

1 file changed

+13
-0
lines changed

src/librustc_mir/build/matches/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
264264
let place =
265265
self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard);
266266
unpack!(block = self.into(&place, block, initializer));
267+
268+
// Inject a fake read of the newly created binding
269+
// to test the fallout of fixing issue #53695 where NLL
270+
// allows to create variables that are immediately unusable.
271+
let source_info = self.source_info(irrefutable_pat.span);
272+
self.cfg.push(
273+
block,
274+
Statement {
275+
source_info,
276+
kind: StatementKind::ReadForMatch(place.clone()),
277+
},
278+
);
279+
267280
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
268281
block.unit()
269282
}

0 commit comments

Comments
 (0)