File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -475,7 +475,18 @@ impl<'tcx> CloneShimBuilder<'tcx> {
475475 where
476476 I : IntoIterator < Item = Ty < ' tcx > > ,
477477 {
478+ // For an iterator of length n, create 2*n + 1 blocks.
478479 for ( i, ity) in tys. into_iter ( ) . enumerate ( ) {
480+ // Each iteration creates two blocks, referred to here as block 2*i and block 2*i + 1.
481+ //
482+ // Block 2*i attempts to clone the field. If successful it branches to 2*i + 2 (the
483+ // next clone block). If unsuccessful it branches to the previous unwind block, which
484+ // is initially the `unwind` argument passed to this function.
485+ //
486+ // Block 2*i + 1 is the unwind block for this iteration. It drops the cloned value
487+ // created by block 2*i. We store this block in `unwind` so that the next clone block
488+ // will unwind to it if cloning fails.
489+
479490 let field = Field :: new ( i) ;
480491 let src_field = self . tcx . mk_place_field ( src, field, ity) ;
481492
@@ -491,6 +502,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
491502 ) ;
492503 unwind = next_unwind;
493504 }
505+ // If all clones succeed then we end up here.
494506 self . block ( vec ! [ ] , TerminatorKind :: Goto { target } , false ) ;
495507 unwind
496508 }
You can’t perform that action at this time.
0 commit comments