Skip to content

Commit 3e26a8d

Browse files
committed
Auto merge of rust-lang#90352 - camsteffen:for-loop-desugar, r=oli-obk
Simplify `for` loop desugar Basically two intermediate bindings are inlined. I could have left one intermediate binding in place as this would simplify some diagnostic logic, but I think the difference in that regard would be negligible, so it is better to have a minimal HIR. For checking that the pattern is irrefutable, I added a special case when the `match` is found to be non-exhaustive. The reordering of the arms is purely stylistic. I don't *think* there are any perf implications. ```diff match IntoIterator::into_iter($head) { mut iter => { $label: loop { - let mut __next; match Iterator::next(&mut iter) { - Some(val) => __next = val, None => break, + Some($pat) => $block, } - let $pat = __next; - $block } } } ```
2 parents 44eab50 + 053bfdd commit 3e26a8d

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

std/src/keyword_docs.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,10 @@ mod fn_keyword {}
549549
/// {
550550
/// let result = match IntoIterator::into_iter(iterator) {
551551
/// mut iter => loop {
552-
/// let next;
553552
/// match iter.next() {
554-
/// Some(val) => next = val,
555553
/// None => break,
554+
/// Some(loop_variable) => { code(); },
556555
/// };
557-
/// let loop_variable = next;
558-
/// let () = { code(); };
559556
/// },
560557
/// };
561558
/// result

0 commit comments

Comments
 (0)