| 618 | } |
| 619 | |
| 620 | fn validate_block(ret_kind: ReturnKind, block: &Block) -> Nested<'_> { |
| 621 | if !matches!(ret_kind, ReturnKind::Iterator) { |
| 622 | // Loops are only allowed if we're returning an iterator. |
| 623 | assert!( |
| 624 | !block |
| 625 | .steps |
| 626 | .iter() |
| 627 | .any(|c| matches!(c.check, ControlFlow::Loop { .. })) |
| 628 | ); |
| 629 | |
| 630 | // Unless we're returning an iterator, a case which returns a result must be the last |
| 631 | // case in a block. |
| 632 | if let Some(result_pos) = block |
| 633 | .steps |
| 634 | .iter() |
| 635 | .position(|c| matches!(c.check, ControlFlow::Return { .. })) |
| 636 | { |
| 637 | assert_eq!(block.steps.len() - 1, result_pos); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | Nested::Cases(block.steps.iter()) |
| 642 | } |
| 643 | |
| 644 | fn block_weight(block: &Block) -> usize { |
| 645 | fn cf_weight(cf: &ControlFlow) -> usize { |