@@ -246,14 +246,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
246
246
} )
247
247
}
248
248
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]`.
250
255
251
256
let loop_block = this. cfg . start_new_block ( ) ;
252
257
253
258
// Start the loop.
254
259
this. cfg . goto ( block, source_info, loop_block) ;
255
260
256
261
this. in_breakable_scope ( Some ( loop_block) , destination, expr_span, |this| {
262
+ // logic for `loop`
257
263
let mut body_block = this. cfg . start_new_block ( ) ;
258
264
this. cfg . terminate (
259
265
loop_block,
@@ -265,6 +271,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
265
271
) ;
266
272
this. diverge_from ( loop_block) ;
267
273
274
+ // logic for `match`
268
275
let scrutinee_place_builder =
269
276
unpack ! ( body_block = this. as_place_builder( body_block, state) ) ;
270
277
let scrutinee_span = this. thir . exprs [ state] . span ;
@@ -282,6 +289,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
282
289
patterns. push ( ( & * arm. pattern , HasMatchGuard :: No ) ) ;
283
290
}
284
291
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.
285
295
let built_tree = this. lower_match_tree (
286
296
body_block,
287
297
scrutinee_span,
@@ -293,6 +303,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
293
303
294
304
let state_place = scrutinee_place_builder. to_place ( this) ;
295
305
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.
296
312
unpack ! (
297
313
body_block = this. in_scope(
298
314
( region_scope, source_info) ,
0 commit comments