@@ -44,7 +44,7 @@ struct AsyncFnVisitor<'a, 'tcx> {
44
44
found_await : bool ,
45
45
/// Also keep track of `await`s in nested async blocks so we can mention
46
46
/// it in a note
47
- found_await_in_async_block : bool ,
47
+ await_in_async_block : Option < Span > ,
48
48
async_depth : usize ,
49
49
}
50
50
@@ -55,8 +55,8 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> {
55
55
if let ExprKind :: Yield ( _, YieldSource :: Await { .. } ) = ex. kind {
56
56
if self . async_depth == 1 {
57
57
self . found_await = true ;
58
- } else {
59
- self . found_await_in_async_block = true ;
58
+ } else if self . await_in_async_block . is_none ( ) {
59
+ self . await_in_async_block = Some ( ex . span ) ;
60
60
}
61
61
}
62
62
walk_expr ( self , ex) ;
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
96
96
cx,
97
97
found_await : false ,
98
98
async_depth : 0 ,
99
- found_await_in_async_block : false ,
99
+ await_in_async_block : None ,
100
100
} ;
101
101
walk_fn ( & mut visitor, fn_kind, fn_decl, body. id ( ) , def_id) ;
102
102
if !visitor. found_await {
@@ -108,8 +108,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
108
108
|diag| {
109
109
diag. help ( "consider removing the `async` from this function" ) ;
110
110
111
- if visitor. found_await_in_async_block {
112
- diag. note ( "`await` used in an async block, which does not require the enclosing function to be `async`" ) ;
111
+ if let Some ( span) = visitor. await_in_async_block {
112
+ diag. span_note (
113
+ span,
114
+ "`await` used in an async block, which does not require \
115
+ the enclosing function to be `async`",
116
+ ) ;
113
117
}
114
118
} ,
115
119
) ;
0 commit comments