@@ -4,7 +4,7 @@ use rustc_errors::Applicability;
4
4
use rustc_hir:: intravisit:: FnKind ;
5
5
use rustc_hir:: {
6
6
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 ,
8
8
} ;
9
9
use rustc_lint:: { LateContext , LateLintPass } ;
10
10
use rustc_middle:: middle:: resolve_bound_vars:: ResolvedArg ;
@@ -60,8 +60,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
60
60
&& let ExprKind :: Block ( block, _) = body. value . kind
61
61
&& block. stmts . is_empty ( )
62
62
&& 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
+ }
65
68
&& !span. from_expansion ( )
66
69
{
67
70
let header_span = span. with_hi ( ret_ty. span . hi ( ) ) ;
@@ -72,7 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
72
75
header_span,
73
76
"this function can be simplified using the `async fn` syntax" ,
74
77
|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)
76
80
&& let Some ( header_snip) = header_span. get_source_text ( cx)
77
81
&& let Some ( ret_pos) = position_before_rarrow ( & header_snip)
78
82
&& let Some ( ( _, ret_snip) ) = suggested_ret ( cx, output)
0 commit comments