@@ -44,7 +44,7 @@ struct AsyncFnVisitor<'a, 'tcx> {
4444 found_await : bool ,
4545 /// Also keep track of `await`s in nested async blocks so we can mention
4646 /// it in a note
47- found_await_in_async_block : bool ,
47+ await_in_async_block : Option < Span > ,
4848 async_depth : usize ,
4949}
5050
@@ -55,8 +55,8 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> {
5555 if let ExprKind :: Yield ( _, YieldSource :: Await { .. } ) = ex. kind {
5656 if self . async_depth == 1 {
5757 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 ) ;
6060 }
6161 }
6262 walk_expr ( self , ex) ;
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
9696 cx,
9797 found_await : false ,
9898 async_depth : 0 ,
99- found_await_in_async_block : false ,
99+ await_in_async_block : None ,
100100 } ;
101101 walk_fn ( & mut visitor, fn_kind, fn_decl, body. id ( ) , def_id) ;
102102 if !visitor. found_await {
@@ -108,8 +108,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
108108 |diag| {
109109 diag. help ( "consider removing the `async` from this function" ) ;
110110
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+ ) ;
113117 }
114118 } ,
115119 ) ;
0 commit comments