@@ -4,7 +4,7 @@ use rustc_errors::Applicability;
44use rustc_hir:: intravisit:: FnKind ;
55use rustc_hir:: {
66 Block , Body , Closure , ClosureKind , CoroutineDesugaring , CoroutineKind , CoroutineSource , Expr , ExprKind , FnDecl ,
7- FnRetTy , GenericBound , ImplItem , Item , Node , OpaqueTy , TraitRef , Ty , TyKind ,
7+ FnRetTy , GenericBound , Node , OpaqueTy , TraitRef , Ty , TyKind ,
88} ;
99use rustc_lint:: { LateContext , LateLintPass } ;
1010use rustc_middle:: middle:: resolve_bound_vars:: ResolvedArg ;
@@ -60,8 +60,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
6060 && let ExprKind :: Block ( block, _) = body. value . kind
6161 && block. stmts . is_empty ( )
6262 && let Some ( closure_body) = desugared_async_block ( cx, block)
63- && let Node :: Item ( Item { vis_span, ..} ) | Node :: ImplItem ( ImplItem { vis_span, ..} ) =
64- cx. tcx . hir_node_by_def_id ( fn_def_id)
63+ && let Some ( vis_span_opt) = match cx. tcx . hir_node_by_def_id ( fn_def_id) {
64+ Node :: Item ( item) => Some ( Some ( item. vis_span ) ) ,
65+ Node :: ImplItem ( impl_item) => Some ( impl_item. vis_span ( ) ) ,
66+ _ => None ,
67+ }
6568 && !span. from_expansion ( )
6669 {
6770 let header_span = span. with_hi ( ret_ty. span . hi ( ) ) ;
@@ -72,7 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
7275 header_span,
7376 "this function can be simplified using the `async fn` syntax" ,
7477 |diag| {
75- if let Some ( vis_snip) = vis_span. get_source_text ( cx)
78+ if let Some ( vis_span) = vis_span_opt
79+ && let Some ( vis_snip) = vis_span. get_source_text ( cx)
7680 && let Some ( header_snip) = header_span. get_source_text ( cx)
7781 && let Some ( ret_pos) = position_before_rarrow ( & header_snip)
7882 && let Some ( ( _, ret_snip) ) = suggested_ret ( cx, output)
0 commit comments