@@ -138,12 +138,11 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
138138 let guar = if cycle_error. cycle [ 0 ] . query . dep_kind == dep_kinds:: layout_of
139139 && let Some ( def_id) = cycle_error. cycle [ 0 ] . query . ty_def_id
140140 && let Some ( def_id) = def_id. as_local ( )
141- && matches ! ( tcx. def_kind( def_id) , DefKind :: Coroutine )
141+ && let def_kind = tcx. def_kind ( def_id)
142+ && matches ! ( def_kind, DefKind :: Coroutine )
142143 {
143- let hir = tcx. hir ( ) ;
144- let coroutine_kind = hir
145- . body ( hir. body_owned_by ( def_id) )
146- . coroutine_kind
144+ let coroutine_kind = tcx
145+ . coroutine_kind ( def_id)
147146 . expect ( "expected coroutine to have a coroutine_kind" ) ;
148147 // FIXME: `def_span` for an fn-like coroutine will point to the fn's body
149148 // due to interactions between the desugaring into a closure expr and the
@@ -158,12 +157,16 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
158157 tcx. sess,
159158 span,
160159 E0733 ,
161- "recursion in an `async fn` requires boxing"
162- ) ;
163- diag. note ( "a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future" ) ;
164- diag. note (
165- "consider using the `async_recursion` crate: https://crates.io/crates/async_recursion" ,
160+ "recursion in {} {} requires boxing" ,
161+ tcx. def_kind_descr_article( def_kind, def_id. to_def_id( ) ) ,
162+ tcx. def_kind_descr( def_kind, def_id. to_def_id( ) ) ,
166163 ) ;
164+ if matches ! ( coroutine_kind, hir:: CoroutineKind :: Async ( _) ) {
165+ diag. note ( "a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future" ) ;
166+ diag. note (
167+ "consider using the `async_recursion` crate: https://crates.io/crates/async_recursion" ,
168+ ) ;
169+ }
167170 let mut called = false ;
168171 for ( i, frame) in cycle_error. cycle . iter ( ) . enumerate ( ) {
169172 if frame. query . dep_kind != dep_kinds:: layout_of {
0 commit comments