Skip to content

Commit 2b9df36

Browse files
committed
fix: async_yields_async wrongly unmangled macros
1 parent 55286e7 commit 2b9df36

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

clippy_lints/src/async_yields_async.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
2-
use clippy_utils::source::snippet;
2+
use clippy_utils::source::{snippet, walk_span_to_context};
33
use clippy_utils::ty::implements_trait;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath};
@@ -94,6 +94,8 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
9494
_ => None,
9595
};
9696
if let Some(return_expr_span) = return_expr_span {
97+
let return_expr_span =
98+
walk_span_to_context(return_expr_span, expr.span.ctxt()).unwrap_or(return_expr_span);
9799
span_lint_hir_and_then(
98100
cx,
99101
ASYNC_YIELDS_ASYNC,

tests/ui/async_yields_async.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,21 @@ fn check_expect_suppression() {
8080
}
8181
};
8282
}
83+
84+
fn issue15552() {
85+
async fn bar(i: i32) {}
86+
87+
macro_rules! call_bar {
88+
() => {
89+
async { bar(5).await }
90+
};
91+
($e:expr) => {
92+
bar($e)
93+
};
94+
}
95+
let x = async { call_bar!(5).await };
96+
//~^ async_yields_async
97+
let y = async { call_bar!().await };
98+
//~^ async_yields_async
99+
//~| async_yields_async
100+
}

tests/ui/async_yields_async.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,21 @@ fn check_expect_suppression() {
8080
}
8181
};
8282
}
83+
84+
fn issue15552() {
85+
async fn bar(i: i32) {}
86+
87+
macro_rules! call_bar {
88+
() => {
89+
async { bar(5) }
90+
};
91+
($e:expr) => {
92+
bar($e)
93+
};
94+
}
95+
let x = async { call_bar!(5) };
96+
//~^ async_yields_async
97+
let y = async { call_bar!() };
98+
//~^ async_yields_async
99+
//~| async_yields_async
100+
}

tests/ui/async_yields_async.stderr

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,40 @@ LL | | CustomFutureType
8989
LL | | };
9090
| |_____- outer async construct
9191

92-
error: aborting due to 6 previous errors
92+
error: an async construct yields a type which is itself awaitable
93+
--> tests/ui/async_yields_async.rs:95:21
94+
|
95+
LL | let x = async { call_bar!(5) };
96+
| --^^^^^^^^^^^^--
97+
| | |
98+
| | awaitable value not awaited
99+
| | help: consider awaiting this value: `call_bar!(5).await`
100+
| outer async construct
101+
102+
error: an async construct yields a type which is itself awaitable
103+
--> tests/ui/async_yields_async.rs:97:21
104+
|
105+
LL | let y = async { call_bar!() };
106+
| --^^^^^^^^^^^--
107+
| | |
108+
| | awaitable value not awaited
109+
| | help: consider awaiting this value: `call_bar!().await`
110+
| outer async construct
111+
112+
error: an async construct yields a type which is itself awaitable
113+
--> tests/ui/async_yields_async.rs:89:21
114+
|
115+
LL | async { bar(5) }
116+
| --^^^^^^--
117+
| | |
118+
| | awaitable value not awaited
119+
| | help: consider awaiting this value: `bar(5).await`
120+
| outer async construct
121+
...
122+
LL | let y = async { call_bar!() };
123+
| ----------- in this macro invocation
124+
|
125+
= note: this error originates in the macro `call_bar` (in Nightly builds, run with -Z macro-backtrace for more info)
126+
127+
error: aborting due to 9 previous errors
93128

0 commit comments

Comments
 (0)