@@ -60,8 +60,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
6060 //
6161 // This also needs special handling because the HirId of the returned `hir::Expr` will not
6262 // 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 ) ;
6565 }
6666 _ => ( ) ,
6767 }
@@ -1679,7 +1679,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16791679 head : & Expr ,
16801680 body : & Block ,
16811681 opt_label : Option < Label > ,
1682- is_await : bool ,
1682+ loop_kind : ForLoopKind ,
16831683 ) -> hir:: Expr < ' hir > {
16841684 let head = self . lower_expr_mut ( head) ;
16851685 let pat = self . lower_pat ( pat) ;
@@ -1710,30 +1710,33 @@ impl<'hir> LoweringContext<'_, 'hir> {
17101710
17111711 let match_expr = {
17121712 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+ }
17371740 } ;
17381741 let arms = arena_vec ! [ self ; none_arm, some_arm] ;
17391742
@@ -1756,21 +1759,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
17561759 // `mut iter => { ... }`
17571760 let iter_arm = self . arm ( iter_pat, loop_expr) ;
17581761
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+ }
17741780 } ;
17751781
17761782 let match_expr = self . arena . alloc ( self . expr_match (
0 commit comments