@@ -138,12 +138,11 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
138
138
let guar = if cycle_error. cycle [ 0 ] . query . dep_kind == dep_kinds:: layout_of
139
139
&& let Some ( def_id) = cycle_error. cycle [ 0 ] . query . ty_def_id
140
140
&& 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 )
142
143
{
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)
147
146
. expect ( "expected coroutine to have a coroutine_kind" ) ;
148
147
// FIXME: `def_span` for an fn-like coroutine will point to the fn's body
149
148
// 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<'_>>
158
157
tcx. sess,
159
158
span,
160
159
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( ) ) ,
166
163
) ;
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
+ }
167
170
let mut called = false ;
168
171
for ( i, frame) in cycle_error. cycle . iter ( ) . enumerate ( ) {
169
172
if frame. query . dep_kind != dep_kinds:: layout_of {
0 commit comments