Skip to content

Commit 368f722

Browse files
committed
add comments
1 parent 7a414de commit 368f722

File tree

1 file changed

+17
-1
lines changed
  • compiler/rustc_mir_build/src/builder/expr

1 file changed

+17
-1
lines changed

compiler/rustc_mir_build/src/builder/expr/into.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
246246
})
247247
}
248248
ExprKind::LoopMatch { state, region_scope, match_span, ref arms } => {
249-
// FIXME add diagram
249+
// Intuitively, this is a combination of a loop containing a labeled block
250+
// containing a match.
251+
//
252+
// The only new bit here is that the lowering of the match is wrapped in a
253+
// `in_const_continuable_scope`, which makes the match arms and their target basic
254+
// block available to the lowering of `#[const_continue]`.
250255

251256
let loop_block = this.cfg.start_new_block();
252257

253258
// Start the loop.
254259
this.cfg.goto(block, source_info, loop_block);
255260

256261
this.in_breakable_scope(Some(loop_block), destination, expr_span, |this| {
262+
// logic for `loop`
257263
let mut body_block = this.cfg.start_new_block();
258264
this.cfg.terminate(
259265
loop_block,
@@ -265,6 +271,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
265271
);
266272
this.diverge_from(loop_block);
267273

274+
// logic for `match`
268275
let scrutinee_place_builder =
269276
unpack!(body_block = this.as_place_builder(body_block, state));
270277
let scrutinee_span = this.thir.exprs[state].span;
@@ -282,6 +289,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
282289
patterns.push((&*arm.pattern, HasMatchGuard::No));
283290
}
284291

292+
// The `built_tree` maps match arms to their basic block (where control flow
293+
// jumps to when a value matches the arm). This structure is stored so that a
294+
// #[const_continue] can figure out what basic block to jump to.
285295
let built_tree = this.lower_match_tree(
286296
body_block,
287297
scrutinee_span,
@@ -293,6 +303,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
293303

294304
let state_place = scrutinee_place_builder.to_place(this);
295305

306+
// this is logic for the labeled block: a block is a drop scope, hence
307+
// `in_scope`, and a labeled block can be broken out of with a `break 'label`,
308+
// hence the `in_breakable_scope`.
309+
//
310+
// Inside of that information for #[const_continue] is stored, and the match is
311+
// lowered in the standard way.
296312
unpack!(
297313
body_block = this.in_scope(
298314
(region_scope, source_info),

0 commit comments

Comments
 (0)