@@ -60,8 +60,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
60
60
//
61
61
// This also needs special handling because the HirId of the returned `hir::Expr` will not
62
62
// correspond to the `e.id`, so `lower_expr_for` handles attribute low}ering itself.
63
- ExprKind :: ForLoop { pat, iter, body, label, is_await } => {
64
- return self . lower_expr_for ( e, pat, iter, body, * label, * is_await ) ;
63
+ ExprKind :: ForLoop { pat, iter, body, label, kind } => {
64
+ return self . lower_expr_for ( e, pat, iter, body, * label, * kind ) ;
65
65
}
66
66
_ => ( ) ,
67
67
}
@@ -1679,7 +1679,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1679
1679
head : & Expr ,
1680
1680
body : & Block ,
1681
1681
opt_label : Option < Label > ,
1682
- is_await : bool ,
1682
+ loop_kind : ForLoopKind ,
1683
1683
) -> hir:: Expr < ' hir > {
1684
1684
let head = self . lower_expr_mut ( head) ;
1685
1685
let pat = self . lower_pat ( pat) ;
@@ -1710,30 +1710,33 @@ impl<'hir> LoweringContext<'_, 'hir> {
1710
1710
1711
1711
let match_expr = {
1712
1712
let iter = self . expr_ident ( head_span, iter, iter_pat_nid) ;
1713
- let next_expr = if is_await {
1714
- // `async_iter_next(unsafe { Pin::new_unchecked(&mut iter) }).await`
1715
- let future = self . expr_mut_addr_of ( head_span, iter) ;
1716
- let future = self . arena . alloc ( self . expr_call_lang_item_fn_mut (
1717
- head_span,
1718
- hir:: LangItem :: PinNewUnchecked ,
1719
- arena_vec ! [ self ; future] ,
1720
- ) ) ;
1721
- let future = self . expr_unsafe ( future) ;
1722
- let future = self . expr_call_lang_item_fn (
1723
- head_span,
1724
- hir:: LangItem :: AsyncIterNext ,
1725
- arena_vec ! [ self ; future] ,
1726
- ) ;
1727
- let kind = self . make_lowered_await ( head_span, future) ;
1728
- self . arena . alloc ( hir:: Expr { hir_id : self . next_id ( ) , kind, span : head_span } )
1729
- } else {
1730
- // `match Iterator::next(&mut iter) { ... }`
1731
- let ref_mut_iter = self . expr_mut_addr_of ( head_span, iter) ;
1732
- self . expr_call_lang_item_fn (
1733
- head_span,
1734
- hir:: LangItem :: IteratorNext ,
1735
- arena_vec ! [ self ; ref_mut_iter] ,
1736
- )
1713
+ let next_expr = match loop_kind {
1714
+ ForLoopKind :: For => {
1715
+ // `match Iterator::next(&mut iter) { ... }`
1716
+ let ref_mut_iter = self . expr_mut_addr_of ( head_span, iter) ;
1717
+ self . expr_call_lang_item_fn (
1718
+ head_span,
1719
+ hir:: LangItem :: IteratorNext ,
1720
+ arena_vec ! [ self ; ref_mut_iter] ,
1721
+ )
1722
+ }
1723
+ ForLoopKind :: ForAwait => {
1724
+ // `async_iter_next(unsafe { Pin::new_unchecked(&mut iter) }).await`
1725
+ let future = self . expr_mut_addr_of ( head_span, iter) ;
1726
+ let future = self . arena . alloc ( self . expr_call_lang_item_fn_mut (
1727
+ head_span,
1728
+ hir:: LangItem :: PinNewUnchecked ,
1729
+ arena_vec ! [ self ; future] ,
1730
+ ) ) ;
1731
+ let future = self . expr_unsafe ( future) ;
1732
+ let future = self . expr_call_lang_item_fn (
1733
+ head_span,
1734
+ hir:: LangItem :: AsyncIterNext ,
1735
+ arena_vec ! [ self ; future] ,
1736
+ ) ;
1737
+ let kind = self . make_lowered_await ( head_span, future) ;
1738
+ self . arena . alloc ( hir:: Expr { hir_id : self . next_id ( ) , kind, span : head_span } )
1739
+ }
1737
1740
} ;
1738
1741
let arms = arena_vec ! [ self ; none_arm, some_arm] ;
1739
1742
@@ -1756,21 +1759,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
1756
1759
// `mut iter => { ... }`
1757
1760
let iter_arm = self . arm ( iter_pat, loop_expr) ;
1758
1761
1759
- let into_iter_expr = if is_await {
1760
- // `::core::async_iter::IntoAsyncIterator::into_async_iter(<head>)`
1761
- let iter = self . expr_call_lang_item_fn (
1762
- head_span,
1763
- hir:: LangItem :: IntoAsyncIterIntoIter ,
1764
- arena_vec ! [ self ; head] ,
1765
- ) ;
1766
- self . arena . alloc ( self . expr_mut_addr_of ( head_span, iter) )
1767
- } else {
1768
- // `::std::iter::IntoIterator::into_iter(<head>)`
1769
- self . expr_call_lang_item_fn (
1770
- head_span,
1771
- hir:: LangItem :: IntoIterIntoIter ,
1772
- arena_vec ! [ self ; head] ,
1773
- )
1762
+ let into_iter_expr = match loop_kind {
1763
+ ForLoopKind :: For => {
1764
+ // `::std::iter::IntoIterator::into_iter(<head>)`
1765
+ self . expr_call_lang_item_fn (
1766
+ head_span,
1767
+ hir:: LangItem :: IntoIterIntoIter ,
1768
+ arena_vec ! [ self ; head] ,
1769
+ )
1770
+ }
1771
+ ForLoopKind :: ForAwait => {
1772
+ // `::core::async_iter::IntoAsyncIterator::into_async_iter(<head>)`
1773
+ let iter = self . expr_call_lang_item_fn (
1774
+ head_span,
1775
+ hir:: LangItem :: IntoAsyncIterIntoIter ,
1776
+ arena_vec ! [ self ; head] ,
1777
+ ) ;
1778
+ self . arena . alloc ( self . expr_mut_addr_of ( head_span, iter) )
1779
+ }
1774
1780
} ;
1775
1781
1776
1782
let match_expr = self . arena . alloc ( self . expr_match (
0 commit comments